Here's the start of my form...
<div ng-form name="CustomerForm" ng-controller="Customer">
Here's my controller...
app.controller('Customer', ['$scope', function ($scope) {
alert($scope.CustomerForm);
}]);
$scope.CustomerForm
is undefined. Shouldn't the form be added to scope?
At the time of your alert statement, CustomerForm isn't within $scope
yet.
Controllers are meant to:
Read more here about controllers.
See here: DEMO
JS:
var app = angular.module('myApp',[]);
app.controller('Customer', ['$scope', function ($scope) {
$scope.getFormName = function(){
console.log($scope.CustomerForm.$name);
}
}]);
HTML:
<div ng-form name="CustomerForm" ng-controller="Customer">
<button ng-click="getFormName()">CLICK</button>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With