import {ScrollDispatchModule} from '@angular/cdk/scrolling';
ScrollDispatcher
Service contained all registered Scrollable references and emits an event when any one of the Scrollable references emit a scrolled event.
Name | Description |
---|---|
|
Map of all the scrollable references that are registered with the service and their scroll event subscriptions. |
ancestorScrolled | |
---|---|
Returns an observable that emits whenever any of the scrollable ancestors of an element are scrolled. |
|
Parameters | |
elementRef ElementRef<any>
|
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<any>
|
|
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 |
|
Parameters | |
auditTimeInMs number = DEFAULT_SCROLL_TIME
|
|
Returns | |
Observable<CdkScrollable | void>
|
|
CdkScrollable
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]
Name | Description |
---|---|
|
|
|
|
|
|
|
elementScrolled | |
---|---|
Returns observable that emits when a scroll event is fired on the host element. |
|
Returns | |
Observable<Event>
|
|
getElementRef | |
---|---|
Gets the ElementRef for the viewport. |
|
Returns | |
ElementRef<HTMLElement>
|
|
measureScrollOffset | |
---|---|
Measures the scroll offset relative to the specified edge of the viewport. This method can be used instead of directly checking scrollLeft or scrollTop, since browsers are not consistent about what scrollLeft means in RTL. The values returned by this method are normalized such that left and right always refer to the left and right side of the scrolling container irrespective of the layout direction. start and end refer to left and right in an LTR context and vice-versa in an RTL context. |
|
Parameters | |
from "top" | "bottom" | "start" | "end" | "left" | "right"
|
The edge to measure from. |
Returns | |
number
|
|
scrollTo | |
---|---|
Scrolls to the specified offsets. This is a normalized version of the browser's native scrollTo method, since browsers are not consistent about what scrollLeft means in RTL. For this method left and right always refer to the left and right side of the scrolling container irrespective of the layout direction. start and end refer to left and right in an LTR context and vice-versa in an RTL context. |
|
Parameters | |
options ExtendedScrollToOptions
|
specified the offsets to scroll to. |
CdkFixedSizeVirtualScroll
A virtual scroll strategy that supports fixed-size items.
Selector: cdk-virtual-scroll-viewport[itemSize]
Name | Description |
---|---|
@Input()
|
The size of the items in the list (in pixels). |
@Input()
|
The number of pixels worth of buffer to render for when rendering new items. Defaults to 200px. |
@Input()
|
The minimum amount of buffer rendered beyond the viewport (in pixels). If the amount of buffer dips below this number, more items will be rendered. Defaults to 100px. |
CdkVirtualForOf
A directive similar to ngForOf
to be used for rendering data inside a virtual scrolling
container.
Selector: [cdkVirtualFor][cdkVirtualForOf]
Name | Description |
---|---|
@Input()
|
The DataSource to display. |
@Input()
|
The template used to stamp out new elements. |
@Input()
|
The size of the cache used to store templates that are not being used for re-use later.
Setting the cache size to |
@Input()
|
The |
|
Emits whenever the data in the current DataSource changes. |
|
Emits when the rendered view of the data changes. |
measureRangeSize | |
---|---|
Measures the combined size (width for horizontal orientation, height for vertical) of all items in the specified range. Throws an error if the range includes items that are not currently rendered. |
|
Parameters | |
range ListRange
|
|
orientation "vertical" | "horizontal"
|
|
Returns | |
number
|
|
CdkVirtualScrollViewport
extends
CdkScrollable
A viewport that virtualizes it's scrolling with the help of CdkVirtualForOf
.
Selector: cdk-virtual-scroll-viewport
Name | Description |
---|---|
@Input()
|
The direction the viewport scrolls. |
@Output()
|
Emits when the index of the first element visible in the viewport changes. |
|
|
|
|
|
|
|
A stream that emits whenever the rendered range changes. |
|
attach | |
---|---|
Attaches a |
|
Parameters | |
forOf CdkVirtualForOf<any>
|
|
checkViewportSize | |
---|---|
Update the viewport dimensions and re-render. |
detach | |
---|---|
Detaches the current |
elementScrolled | |
---|---|
Returns observable that emits when a scroll event is fired on the host element. |
|
Returns | |
Observable<Event>
|
|
getDataLength | |
---|---|
Gets the length of the data bound to this viewport (in number of items). |
|
Returns | |
number
|
|
getElementRef | |
---|---|
Gets the ElementRef for the viewport. |
|
Returns | |
ElementRef<HTMLElement>
|
|
getOffsetToRenderedContentStart | |
---|---|
Gets the offset from the start of the viewport to the start of the rendered data (in pixels). |
|
Returns | |
number | null
|
|
getRenderedRange | |
---|---|
Get the current rendered range of items. |
|
Returns | |
ListRange
|
|
getViewportSize | |
---|---|
Gets the size of the viewport (in pixels). |
|
Returns | |
number
|
|
measureRangeSize | |
---|---|
Measure the total combined size of the given range. Throws if the range includes items that are not rendered. |
|
Parameters | |
range ListRange
|
|
Returns | |
number
|
|
measureRenderedContentSize | |
---|---|
Measure the combined size of all of the rendered items. |
|
Returns | |
number
|
|
measureScrollOffset | |
---|---|
Gets the current scroll offset from the start of the viewport (in pixels). |
|
Parameters | |
from? "top" | "bottom" | "start" | "end" | "left" | "right"
|
The edge to measure the offset from. Defaults to 'top' in vertical mode and 'start' in horizontal mode. |
Returns | |
number
|
|
scrollTo | |
---|---|
Scrolls to the specified offsets. This is a normalized version of the browser's native scrollTo method, since browsers are not consistent about what scrollLeft means in RTL. For this method left and right always refer to the left and right side of the scrolling container irrespective of the layout direction. start and end refer to left and right in an LTR context and vice-versa in an RTL context. |
|
Parameters | |
options ExtendedScrollToOptions
|
specified the offsets to scroll to. |
scrollToIndex | |
---|---|
Scrolls to the offset for the given index. |
|
Parameters | |
index number
|
The index of the element to scroll to. |
behavior ScrollBehavior = 'auto'
|
The ScrollBehavior to use when scrolling. Default is behavior is |
scrollToOffset | |
---|---|
Scrolls to the given offset from the start of the viewport. Please note that this is not always
the same as setting |
|
Parameters | |
offset number
|
The offset to scroll to. |
behavior ScrollBehavior = 'auto'
|
The ScrollBehavior to use when scrolling. Default is behavior is |
setRenderedContentOffset | |
---|---|
Sets the offset from the start of the viewport to either the start or end of the rendered data (in pixels). |
|
Parameters | |
offset number
|
|
to "to-start" | "to-end" = 'to-start'
|
|
setRenderedRange | |
---|---|
Sets the currently rendered range of indices. |
|
Parameters | |
range ListRange
|
|
setTotalContentSize | |
---|---|
Sets the total size of all content (in pixels), including content that is not currently rendered. |
|
Parameters | |
size number
|
|
FixedSizeVirtualScrollStrategy
Virtual scrolling strategy for lists with items of known fixed size.
attach | |
---|---|
Attaches this scroll strategy to a viewport. |
|
Parameters | |
viewport CdkVirtualScrollViewport
|
The viewport to attach this strategy to. |
detach | |
---|---|
Detaches this scroll strategy from the currently attached viewport. |
scrollToIndex | |
---|---|
Scroll to the offset for the given index. |
|
Parameters | |
index number
|
The index of the element to scroll to. |
behavior ScrollBehavior
|
The ScrollBehavior to use when scrolling. |
updateItemAndBufferSize | |
---|---|
Update the item size and buffer size. |
|
Parameters | |
itemSize number
|
The size of the items in the virtually scrolling list. |
minBufferPx number
|
The minimum amount of buffer (in pixels) before needing to render more |
maxBufferPx number
|
The amount of buffer (in pixels) to render when rendering more. |
ViewportScrollPosition
Object that holds the scroll position of the viewport in each direction.
Name | Description |
---|---|
|
|
|
VirtualScrollStrategy
A strategy that dictates which items should be rendered in the viewport.
Name | Description |
---|---|
|
Emits when the index of the first element visible in the viewport changes. |
attach | |
---|---|
Attaches this scroll strategy to a viewport. |
|
Parameters | |
viewport CdkVirtualScrollViewport
|
The viewport to attach this strategy to. |
detach | |
---|---|
Detaches this scroll strategy from the currently attached viewport. |
onContentRendered | |
---|---|
Called when the range of items rendered in the DOM has changed. |
onContentScrolled | |
---|---|
Called when the viewport is scrolled (debounced using requestAnimationFrame). |
onDataLengthChanged | |
---|---|
Called when the length of the data changes. |
onRenderedOffsetChanged | |
---|---|
Called when the offset of the rendered items changed. |
scrollToIndex | |
---|---|
Scroll to the offset for the given index. |
|
Parameters | |
index number
|
The index of the element to scroll to. |
behavior ScrollBehavior
|
The ScrollBehavior to use when scrolling. |
ExtendedScrollToOptions
An extended version of ScrollToOptions that allows expressing scroll offsets relative to the top, bottom, left, right, start, or end of the viewport rather than just the top and left. Please note: the top and bottom properties are mutually exclusive, as are the left, right, start, and end properties.
type ExtendedScrollToOptions = _XAxis & _YAxis & ScrollOptions;
CdkVirtualForOfContext
The context for an item rendered by CdkVirtualForOf
type CdkVirtualForOfContext = {
$implicit: T;
cdkVirtualForOf: DataSource<T> | Observable<T[]> | NgIterable<T>;
index: number;
count: number;
first: boolean;
last: boolean;
even: boolean;
odd: boolean;
};
DEFAULT_SCROLL_TIME
Time in ms to throttle the scrolling events by default.
const DEFAULT_SCROLL_TIME: 20;
DEFAULT_RESIZE_TIME
Time in ms to throttle the resize events by default.
const DEFAULT_RESIZE_TIME: 20;
VIRTUAL_SCROLL_STRATEGY
The injection token used to specify the virtual scrolling strategy.
const VIRTUAL_SCROLL_STRATEGY: InjectionToken<VirtualScrollStrategy>;