1

I have an array of data that include textboxes that binding to ngModel

My problem is that all the textbox (with the same type of parent) binding to the same model.And by changing the element the other element changed.

This is my code:

<ng-template #textbox let-field="field" let-i="i" let-j="j">
  j={{j}}, i={{i}}
  <input [name]="'ctrl' +i+ j" type="text"  [(ngModel)]="data[i].control.fields[j].value" >
</ng-template>

I change the ngModel from "field.value" to [(ngModel)]="data[i].control.fields[j].value" try to fix like here Angular 2 - 2 Way Binding with NgModel in NgFor but it doesnt work.

The weird part it that it is binding just to the same type of parent

enter image description here

24sharon
  • 1,859
  • 7
  • 40
  • 65
  • Would you mind creating a https://stackblitz.com for the same? That can help you solve better. – Amit Chigadani Oct 22 '18 at 05:00
  • Thanks I got the solution by remove the original fields and duplicate the objects (Reference staff) obj.fields = []; for (let i = 0; i<= this.selectedType.fields.length; i++){ obj.fields.push( Object.assign({}, this.selectedType.fields[i])); } this resolve this issue – 24sharon Oct 22 '18 at 05:27

0 Answers0