track cho Angular biết item nào là cùng một entity khi list thay đổi, giúp reuse DOM/component instance thay vì destroy/recreate sai cách.
Ví dụ đúng với dữ liệu có id:
@for (user of users(); track user.id) {
<app-user-row [user]="user" />
}Với list tĩnh có thể track item; hạn chế dùng index nếu list có sort/filter/insert.
Sai track thường gây mất focus input, reset child state hoặc animation bị giật.
track tells Angular which item represents the same entity when a list changes, allowing DOM/component instances to be reused instead of incorrectly destroyed and recreated.
Correct example for data with ids:
@for (user of users(); track user.id) {
<app-user-row [user]="user" />
}For static lists you can track the item; avoid index when the list can be sorted, filtered or inserted into.
Bad tracking often causes lost input focus, reset child state or jumpy animations.