ngFor
by default uses object identity to compare values, this breaks when primitive values (number, string, boolean) are used, because they change identity when modified). Using trackBy
allows to configure ngFor to zse the index instead of identity:
<div *ngFor="let x of array; let i = index;trackBy:trackByIdx">
<input type="number" [(ngModel)]="array[i]">
</div>
trackByIdx(index: number, obj: any): any {
return index;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…