From 192e6b3e4ca59f0c19b6b4c20e3383e79ebab54a Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Mon, 20 Nov 2017 20:02:49 +0100 Subject: [PATCH] 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. --- src/cdk/scrolling/scroll-dispatcher.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cdk/scrolling/scroll-dispatcher.ts b/src/cdk/scrolling/scroll-dispatcher.ts index 4301730314c..5d5c3949777 100644 --- a/src/cdk/scrolling/scroll-dispatcher.ts +++ b/src/cdk/scrolling/scroll-dispatcher.ts @@ -73,6 +73,11 @@ export class ScrollDispatcher { * Returns an observable that emits an event whenever any of the registered Scrollable * references (or window, document, or body) fire a scrolled event. Can provide a time in ms * to override the default "throttle" time. + * + * **Note:** in order to avoid hitting change detection for every scroll event, + * all of the events emitted from this stream will be run outside the Angular zone. + * If you need to update any data bindings as a result of a scroll event, you have + * to run the callback using `NgZone.run`. */ scrolled(auditTimeInMs: number = DEFAULT_SCROLL_TIME): Observable { return this._platform.isBrowser ? Observable.create(observer => {