MCPcopy Create free account
hub / github.com/angular/components / CdkVirtualForOf

Class CdkVirtualForOf

src/cdk/scrolling/virtual-for-of.ts:91–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89 ],
90})
91export class CdkVirtualForOf<T>
92 implements CdkVirtualScrollRepeater<T>, CollectionViewer, DoCheck, OnDestroy
93{
94 private _viewContainerRef = inject(ViewContainerRef);
95 private _template = inject<TemplateRef<CdkVirtualForOfContext<T>>>(TemplateRef);
96 private _differs = inject(IterableDiffers);
97 private _viewRepeater = new _RecycleViewRepeaterStrategy<T, T, CdkVirtualForOfContext<T>>();
98 private _viewport = inject(CDK_VIRTUAL_SCROLL_VIEWPORT, {skipSelf: true});
99
100 /** Emits when the rendered view of the data changes. */
101 readonly viewChange = new Subject<ListRange>();
102
103 /** Subject that emits when a new DataSource instance is given. */
104 private readonly _dataSourceChanges = new Subject<DataSource<T>>();
105
106 /** The DataSource to display. */
107 @Input()
108 get cdkVirtualForOf(): DataSource<T> | Observable<T[]> | NgIterable<T> | null | undefined {
109 return this._cdkVirtualForOf;
110 }
111 set cdkVirtualForOf(value: DataSource<T> | Observable<T[]> | NgIterable<T> | null | undefined) {
112 this._cdkVirtualForOf = value;
113 if (isDataSource(value)) {
114 this._dataSourceChanges.next(value);
115 } else {
116 // If value is an an NgIterable, convert it to an array.
117 this._dataSourceChanges.next(
118 new ArrayDataSource<T>(isObservable(value) ? value : Array.from(value || [])),
119 );
120 }
121 }
122
123 _cdkVirtualForOf: DataSource<T> | Observable<T[]> | NgIterable<T> | null | undefined;
124
125 /**
126 * The `TrackByFunction` to use for tracking changes. The `TrackByFunction` takes the index and
127 * the item and produces a value to be used as the item's identity when tracking changes.
128 */
129 @Input()
130 get cdkVirtualForTrackBy(): TrackByFunction<T> | undefined {
131 return this._cdkVirtualForTrackBy;
132 }
133 set cdkVirtualForTrackBy(fn: TrackByFunction<T> | undefined) {
134 this._needsUpdate = true;
135 this._cdkVirtualForTrackBy = fn
136 ? (index, item) => fn(index + (this._renderedRange ? this._renderedRange.start : 0), item)
137 : undefined;
138 }
139 private _cdkVirtualForTrackBy: TrackByFunction<T> | undefined;
140
141 /** The template used to stamp out new elements. */
142 @Input()
143 set cdkVirtualForTemplate(value: TemplateRef<CdkVirtualForOfContext<T>>) {
144 if (value) {
145 this._needsUpdate = true;
146 this._template = value;
147 }
148 }

Callers

nothing calls this directly

Calls 1

_changeDataSourceMethod · 0.95

Tested by

no test coverage detected