我在模板中看到了这一点。他们说这是可以测试的,但我似乎仍然是错误的:
<tr ng-repeat="comp in collection">
<td>
<span id="someId">{{comp.someText}}</span>
</td>
....
我认为我们应该使用名称。
如果您确实需要中继器中的唯一ID,请尝试以下操作:
<tr ng-repeat="comp in collection">
<td>
<span id="someId{{$index}}">{{comp.someText}}</span>
</td>
因此,例如,如果您需要将标签链接到ngrepeat中的输入:
<tr ng-repeat="comp in collection">
<td>
<label for="field{{$index}}">{{field.label}}</label>
<input type="text" id="field{{$index}}" ng-model="field.value" />
</td>
如果您需要在ngrepeat内有可点击标签的复选框。