I need to perform form validation for several forms that need to be created dynamically. I created forms dynamically using ng-repeat but I cannot access this form in the controller.
Please check the code:
<button ng-click="navigate()">Next</button>
<div ng-repeat="service in services">
<ng-form name="mainform">
<div ng-repeat="spec in service.products">
<ng-form name="subform">
<input type="text" name="{{spec.name}}" ng-model="spec.value">
<span ng-show="subform[spec.name].$invalid">please enter</span>
</ng-form>
</div>
</ng-form>
</div >
It works fine, but I need to check if at least one of the main subforms is valid or not after clicking on the next button, so I tried to access this in the controller as follows:
$scope.navigate=function(){
console.log($scope.mainform.subform);
console.log($scope.subform);
}
but I get undefinedfor both console logs. How can I access several dynamically created forms in the controller?