Angular2 - 如何将 TextBox 放入 *ngFor

Angular2 - How to put TextBox in *ngFor

我正在尝试在 *ngFor 中添加一个文本框

<tr *ngFor="let abc in _Apple">    
  <td>{{abc.Name}}</td>
  <td> <input matInput  name="UnitofPrice" [(ngModel)] = "UnitofPrice">
</td>
<td>{{UnitofPrice}}</td>

如果我在 UnitofPrice 中输入任何内容,它会反映给所有人。 我怎样才能删除它?

使用 ngFor 索引使您的 NG 模型独一无二: 参见示例:

<tr *ngFor="let abc in _Apple; let i = index;">

<td>{{abc.Name}}</td>
<td> <input matInput  name="UnitofPrice" [(ngModel)]="abc[i]">
</td>
<td>{{UnitofPrice}}</td>

在您的按钮或提交函数中将其作为参数传递,例如:

<button (click)="yourFunc(abc[i])">submit</button>