NG.III · Angular 22 practice question
A developer is rendering a list of user profiles using the new `@for` block. When the list items are reordered but the underlying objects themselves are not replaced, what is the primary benefit of supplying a unique `track` expression?
@for (user of users; track user.id) {
<div>{{ user.name }}</div>
}
Check answer and explanation
Correct answer: Angular will reuse the existing DOM elements for the profiles, only updating the necessary data bindings instead of rebuilding the entire list structure.
Explanation
The correct approach is to allow Angular to reuse the existing DOM elements for the profiles, modifying only the necessary data bindings rather than rebuilding the entire list structure. This is because when a tracked property changes while the object reference remains constant, Angular updates the view's bindings instead of destroying and recreating the entire element.
Common trap
The suggestion that the application will automatically use the element's index if a unique ID is not explicitly provided is flawed because using the index is only appropriate for collections that do not change their order, and the assertion that the rendering process will always destroy and recreate the DOM nodes because object references change during reordering is incorrect, as reference identity comparison is discouraged due to performance issues.
Source: Angular docs: Control flow — Why is `track` in `@for` blocks important?
Checked against the cited text on 2026-11-25.