【发布时间】:2017-01-13 04:26:59
【问题描述】:
这是我的 Angular2 应用程序,表格内有输入字段。我的数据显示在select 标签上,但在input 标签上使用ngModel 绑定的数据未显示在input 字段中。
<form name="userForm">
<table>
<tr *ngFor="let item of itemList; let in =index">
<td><select><option >{{item.FirstName}}</option></select></td>
<td><input type="text" id="lastname" name="lastname" [(ngModel)]="itemList[in].lastname"></td>
<td><input type="text" id="middlename" name="middlename" [(ngModel)]="itemList[in].middlename"></td>
</tr>
</table>
</form>
【问题讨论】:
-
能否请您从输入标签中删除 id,这将导致 DOM 中的多个元素具有相同的 id,因为您在 for 循环中运行它。为什么不使用
item.lastname和item.middlename而不是item[in].lastname -
我确定您必须在各自的组件中导入了
FormsModule。
标签: angular