angular ng在name属性中重复$ index

时间:2014-02-07 15:22:23

标签: javascript angularjs angularjs-ng-repeat

<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,我有必要的字段。我有表单对象$ scope.prForm - 我看到$ error。问题在于名称=“{{'qty_'+ $ index}}”。在$ scope.prForm中我有字段

{{'qty_' + $index}}: instantiate.c

但我需要

qty_0: instantiate.c

如何在name属性中执行良好的{{'qty_'+ $ index}}操作?

2 个答案:

答案 0 :(得分:9)

非常简单:

name="qty_{{$index}}"

以下是plunk,了解其运作方式。

答案 1 :(得分:1)

试试这个:

id="qty_{{$index}}"  

:)