I need help please, I've been trying for couples of days to create a grid with objects that I then insert into an array. Each row in the grid represents the object with a select dropdown and list of colomns with input box. My problem is that when I change a value of headItem that represents my input box, the value is saved to all the objects in the array via (onRowClick()). I was wondering if I can set ngModel on a row to update only values of that row.
NB: the DOM objects are showing correctly because I index the headItem value headItem.value[childIndex]
<tr *ngFor='#row of listRows; #parentIndex = index'>
<td>
<select
[(ngModel)]="color[parentIndex]"
(ngModelChange)="sendColorEvent($event, row)"
class="form-control">
<option *ngFor='#obj of row.availableColors'>{{obj}}</option>
</select>
</td>
<td *ngFor='#headItem of row.headList; #childIndex = index'>
<input [(ngModel)]="headItem.value[childIndex]" (ngModelChange)="onRowClick($event, row, headItem)" type="number">
<td>
<input readonly="readonly" [(ngModel)]="totalAmount" type="number">
</td>
</tr>
In the console log you can see that in array all the row have the same value, the last typed.
onRowClick(quantity, row, headItem) {
headItem.value = quantity;
console.log(this.listRows)
this.getTotal();
}