Think about how rendering fewer elements affects browser speed.
Virtual scrolling renders only the visible items plus a small buffer, reducing DOM size and improving performance especially for large lists.
Angular inputs use camelCase and square brackets for binding.
The correct input property is itemSize with camelCase, and binding uses square brackets for dynamic values.
<cdk-virtual-scroll-viewport [itemSize]="50" class="viewport">
<div *cdkVirtualFor="let item of items" class="item">{{item}}</div>
</cdk-virtual-scroll-viewport>If the viewport shows empty space and no items, what is the most likely cause?
Check if the container has a height to show scrollable content.
The virtual scroll viewport requires a fixed height set by CSS to display and scroll items properly. Without height, it collapses and shows blank space.
items = Array.from({length: 1000}, (_, i) => `Item ${i+1}`);
onScrollIndexChange(index: number) {
console.log('Start index:', index);
}And the template:
<cdk-virtual-scroll-viewport [itemSize]="20" (scrolledIndexChange)="onScrollIndexChange($event)">
<div *cdkVirtualFor="let item of items">{{item}}</div>
</cdk-virtual-scroll-viewport>What will be logged when the user scrolls down the list?
Check what the scrolledIndexChange event emits.
The scrolledIndexChange event emits the index of the first visible item in the viewport during scrolling.
Think about how fixed size assumptions affect scrolling calculations.
Virtual scrolling relies on fixed item sizes to calculate which items to render and scroll offsets. Dynamic heights break these calculations, causing glitches.