@pascalpuetz has the right answer.
Here's a more more specific example though:
If a card would have this interface:
interface Card {
id: string; // a value that uniquely identifies a card
type: 'error' | 'success' | 'warning';
message: string;
delay: number;
}
You could track them by a unique property of the Card object like the id.
trackCardsById(index: number, card: Card) {
return card.id;
}
<div *ngFor="let card of cards; trackBy:trackCardsById " class="card" [ngClass]="card.type">
{{card.message}}
</div>
Or you could track them by their position in the list:
trackCardsByIndex(index: number, card: Card) {
return index;
}
<div *ngFor="let card of cards; trackBy:trackCardsByIndex " class="card" [ngClass]="card.type">
{{card.message}}
</div>
You can see a working example here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…