Skip to content

Commit 192e6b3

Browse files
crisbetojelbourn
authored andcommitted
docs(scroll-dispatcher): add note about callback being run outside the NgZone (#8545)
Since the `scrolled` events are being run outside the NgZone, it might be confusing if people decide to update their view as a result of a scroll event. These changes add a note on the method docs to avoid some of the confusion. Relates to #8279.
1 parent 49c6cbc commit 192e6b3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/cdk/scrolling/scroll-dispatcher.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ export class ScrollDispatcher {
7373
* Returns an observable that emits an event whenever any of the registered Scrollable
7474
* references (or window, document, or body) fire a scrolled event. Can provide a time in ms
7575
* to override the default "throttle" time.
76+
*
77+
* **Note:** in order to avoid hitting change detection for every scroll event,
78+
* all of the events emitted from this stream will be run outside the Angular zone.
79+
* If you need to update any data bindings as a result of a scroll event, you have
80+
* to run the callback using `NgZone.run`.
7681
*/
7782
scrolled(auditTimeInMs: number = DEFAULT_SCROLL_TIME): Observable<CdkScrollable|void> {
7883
return this._platform.isBrowser ? Observable.create(observer => {

0 commit comments

Comments
 (0)