Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular ngRepeat $index 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?

like image 246
user1005180 Avatar asked Dec 25 '22 13:12

user1005180


1 Answers

Very easy:

name="qty_{{$index}}"

Here is a plunk to see how it work.

like image 128
SET Avatar answered Dec 28 '22 05:12

SET