Recall & Review
beginner
What is the purpose of
*ngFor in Angular?*ngFor is a directive used to repeat a block of HTML for each item in a list or array. It helps display lists dynamically.
Click to reveal answer
beginner
How do you write a basic
*ngFor loop to display items from an array called items?<pre><li *ngFor="let item of items">{{ item }}</li></pre><p>This repeats the <li> element for each <code>item</code> in <code>items</code>.</p>Click to reveal answer
beginner
What does the keyword <code>let</code> mean in <code>*ngFor="let item of items"</code>?let declares a local variable item that holds the current element from the items array during each iteration.
Click to reveal answer
intermediate
How can you access the index of the current item in an
*ngFor loop?<pre><li *ngFor="let item of items; let i = index">{{ i }} - {{ item }}</li></pre><p>The <code>index</code> keyword gives the zero-based position of the current item.</p>Click to reveal answer
advanced
Why is it important to use
trackBy with *ngFor in large lists?trackBy helps Angular identify items uniquely to optimize rendering and avoid unnecessary DOM updates, improving performance.
Click to reveal answer
What does
*ngFor="let item of items" do in Angular?✗ Incorrect
*ngFor repeats the element for each item in the array, rendering a list.
How do you get the current index inside an
*ngFor loop?✗ Incorrect
The keyword index gives the current zero-based index.
What is the role of
trackBy in *ngFor?✗ Incorrect
trackBy helps Angular track items uniquely to avoid re-rendering unchanged elements.
Which of these is the correct syntax to loop over an array
users with *ngFor?✗ Incorrect
The correct syntax is let variable of array.
What happens if you forget to use
let in *ngFor?✗ Incorrect
let is required to declare the loop variable; missing it causes a syntax error.
Explain how
*ngFor works to render lists in Angular. Include how to access the current item and its index.Think about how you would show a list of names with their position numbers.
You got /3 concepts.
Describe why using
trackBy with *ngFor can improve performance in Angular applications.Imagine updating a long list where only one item changes.
You got /3 concepts.