I have an array that I'm showing on a table, but I need to edit all the values in one column of that table. My code is like this:
<tr *ngFor="let line of invoice.lines; let index = index">
<td>
{{line.quantity}}
</td>
<td style="width: 35%">
{{line.productName}}
</td>
<td>
<input type="number" class="form-control" name="order_price"
id="field_order_price" [(ngModel)]="line.price"/>
</td>
...
</tr>
The thing is that the input
has the same value in all the rows (which is the last one in the array). I tried printing the value of line.price
next to the input
to be sure that the I'm getting the right values and this is what I get:
What am I missing?
UPDATE 1: changed by suggstions hasn't worked :(
<input type="number" class="form-control" name="order_price" (click)="onOrderPriceChange(index)" id="field_order_price1_{{index}}" [(ngModel)]="invoice.lines[index].price"/>
Angular:
trackByIndex(index: number, line: IInvoiceLine): any {
return line.id;
}