【发布时间】:2017-09-06 01:51:07
【问题描述】:
首先,如果使用 [(ngModel)] 绑定输入,我不明白为什么 Angular 2 需要名称属性。否则,我会收到此错误:
ERROR Error: If ngModel is used within a form tag, either the name
attribute must be set or the form control must be defined as
'standalone' in ngModelOptions.
这通常不是问题,但我如何使用 *ngFor 在循环中执行此操作?索引(如角度 1 中的 $index)可用吗?
【问题讨论】:
-
你不能使用你正在迭代的名字吗?
-
*ngFor="let foo of bars; let i=index"然后你可以使用i变量。