Scrolling

API for scrolling

API reference for Angular CDK scrolling

import {ScrollDispatchModule} from '@angular/cdk/scrolling';

Service contained all registered Scrollable references and emits an event when any one of the Scrollable references emit a scrolled event.

Properties
NameDescription

scrollContainers: Map<CdkScrollable, Subscription>

Map of all the scrollable references that are registered with the service and their scroll event subscriptions.

Methods
ancestorScrolled

Returns an observable that emits whenever any of the scrollable ancestors of an element are scrolled.

Parameters

elementRef

ElementRef

Element whose ancestors to listen for.

auditTimeInMs?

number

Time to throttle the scroll events.

Returns
Observable<CdkScrollable | void>

deregister

Deregisters a Scrollable reference and unsubscribes from its scroll event observable.

Parameters

scrollable

CdkScrollable

Scrollable instance to be deregistered.

getAncestorScrollContainers

Returns all registered Scrollables that contain the provided element.

Parameters

elementRef

ElementRef

Returns
CdkScrollable[]

register

Registers a scrollable instance with the service and listens for its scrolled events. When the scrollable is scrolled, the service emits the event to its scrolled observable.

Parameters

scrollable

CdkScrollable

Scrollable instance to be registered.

scrolled

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.

Parameters

auditTimeInMs

number = DEFAULT_SCROLL_TIME

Returns
Observable<CdkScrollable | void>

Sends an event when the directive's element is scrolled. Registers itself with the ScrollDispatcher service to include itself as part of its collection of scrolling events that it can be listened to through the service.

Selector: [cdk-scrollable] [cdkScrollable]

Methods
elementScrolled

Returns observable that emits when a scroll event is fired on the host element.

Returns
Observable<any>

getElementRef
Returns
ElementRef