javascript 名称属性中的角度 ngRepeat $index
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21631456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
angular ngRepeat $index in name attribute
提问by user1005180
<div ng-repeat="fod in form.order_details">
...
<td class="control-cell">
<span ng-class="{error: prForm['qty_'+$index].$error.required && showValidationMessages}">
<input type="number" name="{{'qty_' + $index}}" ng-model="fod.qty" ng-change="qtyPerKindCalc($index);" id="{{'qty_' + $index}}" required />
<span ng-show="prForm['qty_'+$index].$error.required && showValidationMessages" class="error-msg">This field required</span>
</span>
</td>
...
</div>
ngRepeat, where i'm have required field. I'm have form object $scope.prForm - where i'm see $error. Problem is in name="{{'qty_' + $index}}". In $scope.prForm i'm have field
ngRepeat,我在这里有必填字段。我有表单对象 $scope.prForm - 在那里我看到 $error。问题在于 name="{{'qty_' + $index}}"。在 $scope.prForm 我有字段
{{'qty_' + $index}}: instantiate.c
but i'm need
但我需要
qty_0: instantiate.c
How I can have good {{'qty_' + $index}} operation in name attribute?
如何在 name 属性中进行良好的 {{'qty_' + $index}} 操作?
回答by SET
回答by Artyom Pranovich
Try this:
试试这个:
id="qty_{{$index}}"
:)
:)