Reputation: 1978
I can make the loop but I do not understand why it only shows me the value of the last record
invoice-list.html
<ng-template ngFor let-i [ngForOf]="invoiceService.selectedInvoice.purchases">
{{i.product.name | json}}
<input type="text" name="name" class="form-control" #pname="ngModel" [(ngModel)]="i.product.name" readonly>
</ng-template>
here's an example StackBlitz (login => user:[email protected] | pass: user123)
Upvotes: 0
Views: 499
Reputation: 11000
Because you use two way binding NgModel
which binds incoming value to the same variable - i.product.name
. It doesn't makes much sense to use ngModel here. You export your form with #invoiceFrom='NgForm
so you can do all validations there. Simply pass a value:
<input type="text" name="name" class="form-control [value]="i.product.name" readonly>
Upvotes: 1