(Editing Angular 5) I can't get the values of the object that is in NgModel

Issue

I could not get the object of this field

component.html

<div class="form-group">
    <input type="number" name="totalPrice" class="form-control" #lastname="ngModel"[(ngModel)]="invoiceService.selectedInvoice.totalPrice" readonly>
</div> <!-- working ok -->
<div class="form-group">
      <input type="number" name="purchases" class="form-control" #purchases="ngModel" [(ngModel)]="invoiceService.selectedInvoice.purchases['product']" readonly>
</div><!-- not working -->

this the element

enter image description here

Any idea?

here’s an example (login => user:user@user.com | pass: user123) StackBlitz

Solution

Finally this was the solution. It does not work because i use two way binding NgModel which binds incoming value to the same variable – i.product.name

<ng-template ngFor let-i [ngForOf]="invoiceService.selectedInvoice.purchases"> 
    {{i.product.name | json}}   
    <input type="text" name="purchases" class="form-control" [value]="i.product.name" readonly>
</ng-template>

Answered By – Rafael Corzo

Answer Checked By – Pedro (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.