0
0
Angularframework~20 mins

Virtual scrolling for large lists in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Virtual Scroll Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Angular's virtual scrolling improve performance?
Angular's CDK virtual scrolling renders only a subset of list items visible in the viewport. What is the main benefit of this approach?
AIt duplicates list items to fill the viewport faster.
BIt preloads all list items in the background to speed up scrolling.
CIt reduces memory and DOM nodes by rendering only visible items, improving scroll performance.
DIt disables scrolling until all items are rendered to avoid lag.
Attempts:
2 left
💡 Hint

Think about how rendering fewer elements affects browser speed.

📝 Syntax
intermediate
2:00remaining
Identify the correct syntax for using Angular CDK virtual scroll viewport
Which option shows the correct way to set up a virtual scroll viewport with a fixed item size of 50 pixels?
A<cdk-virtual-scroll-viewport [itemSize]="50">...</cdk-virtual-scroll-viewport>
B<cdk-virtual-scroll-viewport itemSize="50">...</cdk-virtual-scroll-viewport>
C<cdk-virtual-scroll-viewport item-size="50">...</cdk-virtual-scroll-viewport>
D<cdk-virtual-scroll-viewport [item-size]="50">...</cdk-virtual-scroll-viewport>
Attempts:
2 left
💡 Hint

Angular inputs use camelCase and square brackets for binding.

🔧 Debug
advanced
2:00remaining
Why does the virtual scroll viewport show blank space instead of items?
Given this Angular template snippet:
<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?
AThe items array is empty or undefined, so nothing renders.
BThe itemSize input is missing or set to zero, so viewport cannot calculate visible items.
CThe *cdkVirtualFor directive is misspelled, causing no rendering.
DThe viewport height is not set via CSS, so it collapses and hides items.
Attempts:
2 left
💡 Hint

Check if the container has a height to show scrollable content.

state_output
advanced
2:00remaining
What is the output when scrolling triggers an event in virtual scroll?
Consider this Angular component snippet:
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?
AThe last visible item's index in the viewport after scrolling.
BThe index of the first visible item in the viewport as the user scrolls.
CThe total number of items in the list each time scrolling happens.
DThe scroll position in pixels from the top of the list.
Attempts:
2 left
💡 Hint

Check what the scrolledIndexChange event emits.

🧠 Conceptual
expert
3:00remaining
Why might virtual scrolling cause issues with dynamic item heights?
Virtual scrolling in Angular CDK assumes fixed item heights for calculations. What problem arises if list items have dynamic heights?
AThe viewport cannot correctly calculate scroll positions, causing visual glitches or incorrect item rendering.
BThe scroll bar disappears because the list height is fixed.
CDynamic heights improve performance by reducing DOM nodes automatically.
DThe virtual scroll automatically adjusts heights, so no issues occur.
Attempts:
2 left
💡 Hint

Think about how fixed size assumptions affect scrolling calculations.