You could also use the trackBy
option in your *ngFor
expression, providing a unique ID for every item inside the array. This does make you 100% responsible for change detection, so update this (unique) property every time the item in the array changes. Angular will then only re-render the list if any item inside your array has been given a different trackBy
property:
*ngFor="let item of (itemList$ | async); trackBy: trackItem"
or:
*ngFor="let item of itemList; trackBy: trackItem"
where:
trackItem
is a public method in your component:
public trackItem (index: number, item: Item) {
return item.trackId;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…