CodeZettaInterview Hub

Angular · Templates · Fresh / Intern · Scenario

How does @for track items and why does track matter?

Short Interview Answer

@for requires a track expression to identify items across updates for efficient DOM reuse.

Detailed Explanation

Tracking by identity (id) prevents destroying/recreating DOM when the list reorders. track $index is a last resort. Wrong track keys cause state bugs in inputs inside lists.

Example

@for (item of items(); track item.id) {
  <li>{{ item.name }}</li>
}

Did you know this answer?