How to access an unknown form in the controller?

I have more than three dynamically generated forms. I need to repeat all form errors in the controller. I assign forms names using models.

<form name="{{myForm}}" novalidate>     
<input type="text" ng-model="username" name="username" required/>
<span ng-show="(submit && myForm.username.$error.required)">
    <span>Required</span>
</span>

angular.module("myApp",[]).controller("myCtrl",function($scope) {
$scope.myForm= "validateForm";      
console.log("form" + $scope.myForm)
});

What I want, when I console $scope.myForm, it should print the form object, but what happens is that it just prints the line "validateForm".

0
source share
1 answer

Ultimately, you want to $scope.validateForm, since "validateForm"is the name you give the form after compilation name="{{myForm}}":

You can get it from $scope[$scope.myForm]

, , .

, , - ,

0

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


All Articles