Rather than using $index
do use some unique property, may be item has its own id
property which defines uniqueness of item. So ng-init
will look like formName = 'item_details' + item.id"
<div ng-repeat="item in itemList" ng-init="formName = 'item_details' + item.id">
<form name="{{formName}}" ng-class="validateForm(formName)">
//few form elements
</form>
</div>
Even I'm wondering what is need behind you are making each form with unique name? You can have nested forms and innerForm
will get validated lonely. Thereafter the way validation will handle is, when all innerForm
gets valid, outForm
is valid. When any of the innerForm
is invalid outerForm
will be invalid in that case.
<ng-form ng-repeat="item in itemList" name="outerform">
<form name="innerForm" ng-class="validateForm(innerForm)">
//few form elements
</form>
</div>