admin管理员组

文章数量:1341736

<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

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

but i'm need

qty_0: instantiate.c

How I can have good {{'qty_' + $index}} operation in name attribute?

<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

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

but i'm need

qty_0: instantiate.c

How I can have good {{'qty_' + $index}} operation in name attribute?

Share asked Feb 7, 2014 at 15:22 user1005180user1005180 811 gold badge1 silver badge10 bronze badges 2
  • name="qty_{{$index}}" ? – SET001 Commented Feb 7, 2014 at 15:31
  • 1 Solution with dynamically names: stackoverflow./a/12044600/1005180 – user1005180 Commented Feb 7, 2014 at 16:15
Add a ment  | 

2 Answers 2

Reset to default 9

Very easy:

name="qty_{{$index}}"

Here is a plunk to see how it work.

Try this:

id="qty_{{$index}}"  

:)

本文标签: javascriptangular ngRepeat index in name attributeStack Overflow