trackBy
Introduction
Section titled “Introduction”Without trackBy, Angular destroys and recreates all DOM nodes when the array reference changes. trackBy identifies items by a stable key.
Example
Section titled “Example”@Component({ template: ` <li *ngFor="let user of users; trackBy: trackByUserId"> {{ user.name }} </li> `})export class UsersComponent { trackByUserId(index: number, user: User): number { return user.id; }}Summary
Section titled “Summary”Always use trackBy with *ngFor for lists with more than a few items.”