POV
POV

Reputation: 12025

How to use ngModel in ngFor?

Why this code is not working:

model:any = {};

<tr *ngFor="let item of items">
  <td><input [ngModel]="model[id]" size="7" /></td>
</tr>

It says there is no id inside model. How to use ngModel properly in *ngFor?

Upvotes: 0

Views: 61

Answers (1)

Adrita Sharma
Adrita Sharma

Reputation: 22203

Try like this:

TS:

model = [];

Template:

<input size="7"  (change)="model[item.id]=$event.target.value"/>

Upvotes: 1

Related Questions