Premise: I tried several answers (including one I asked and accidentally accepted) but none works for me.
I have a nested ngFor inside and a nested binding via ngModel.
Issue: when I update one item in the nested ngFor the corresponding item is update also in the other nested ngFor. Example code below with comment what work and what doesn't.
template
<div *ngFor="let outerObject of outerObjects; let oIndex = index; trackBy: trackByIndex">
{{outerObject.value}} <!-- this works -->
<div *ngFor="let innerObject of outerObject.innerObjects; let index = index; trackBy: trackByIndex">
<input [(ngModel)]="outerObject.innerObjects[index]"> <!-- when I change this any innerObjects[i] is updated -->
</div>
</div>
ts
outerObjects = [
{
value = 'x'
innerObjects: ['a', 'b', 'c']
},
{
value = 'y'
innerObjects: ['a', 'b', 'c']
}
];
trackByIndex(index: number, obj: any): any {
return index;
}