I'm trying to access form object in my controller. Form lies inside ng-repeat block it has got its dynamic name and I should be able to access it since v1.3.
js:
var app = angular.module('app', []);
app.controller('AppCtrl', ['$scope', function($scope) {
$scope.forms = [0];
$scope.testForm = function() {
if($scope.form0 == undefined) {
$scope.test = 'Form is NOT defined';
} else {
$scope.test = 'Form is defined';
}
}
}])
html:
<body ng-app="app">
<div ng-controller="AppCtrl">
<div ng-repeat="form in forms" ng-init="formName = 'form' + $index">
form name should be {{formName}}
<form name="{{formName}}">
<input type="text" name="field" />
</form>
</div>
<button ng-click="testForm()">Check if form exists</button>
<p ng-bind="test"></p>
</div>
</body>
But in my controller $scope.form0 is undefined - after clicking "Check if form exists" I get "Form is NOT defined" message. Even if I give it a static name (<form name="form0">) I still keep getting undefined. When I take form out of the ng-repeat loop, it works fine.
Any idea why it is not set?
The example above: https://plnkr.co/edit/Fvy5LdIO0H1vCS9wYR0U?p=preview
Thanks in advance!