...

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 have a required field. I have a $ scope.prForm form object - where I see $ error. The problem is name = "{{'qty_' + $ index}}." In $ scope.prForm, I have a field

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

but i need

qty_0: instantiate.c

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

+4
source share
3 answers

Very simple:

name="qty_{{$index}}"

Here is a plunk to see how it works.

+7
source

Try the following:

id="qty_{{$index}}"  

:)

+1
source

, , . ng-repeat 1000 ( ), <input> 0 ( ). , "name" <input>, 0 uncompiled "myName_$index" , . ( "index" -directive, 999, ng-repeat), , , .

0

Source: https://habr.com/ru/post/1525807/


All Articles