Nove124
Nove124

Reputation: 233

Angular clear editable fields of table problem

I have problem. When i want to add new row to table. It clears all previous rows.

This way i push new empty element.

  testFunc()
   {

     //console.log(this.ProcessVATElems[this.elemIter].Lp); 
      this.ProcessVATElems[this.elemIter].Lp = ++this.elemIter;
      var elem = new ProcessVatElement()
      elem.Lp = 0;
      this.ProcessVATElems.push(elem);
      console.log(this.ProcessVATElems);
      console.log(this.elemIter);
   }

This is an example of my binding in html

  <td>
<input type="text" class="form-control  smallOpt" name="att23" [(ngModel)]="ProcessVATElems[index].NetValue"  
[disabled]="End" id="Dom" placeholder="" style="width:50pt; height: 22pt;  margin-left: 1pt;">
  </td>

This is my table before adding new row. enter image description here

And after ( I add new row by call testFunc() ) enter image description here

To add new row i click on table element where Lp == 0

<td (click)="testFunc()" >
{{elem.Lp}}
</td>

Upvotes: 0

Views: 95

Answers (1)

Adrian Brand
Adrian Brand

Reputation: 21638

You need a unique name for each input

[name]="'att23_' + index"

Upvotes: 1

Related Questions