表单元素没有出现在$范围 [英] Form elements not appearing in $scope
本文介绍了表单元素没有出现在$范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的形式开始...
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
是不确定的。不应形式加入到范围?
$scope.CustomerForm
is undefined. Shouldn't the form be added to scope?
推荐答案
在你的警报语句的时候,CustomerForm不是 $范围
尚未以内。
At the time of your alert statement, CustomerForm isn't within $scope
yet.
控制器是为了:
- 创建一个范围对象的初始状态。
- 添加行为的范围对象。
这里更多约控制器。
Read more here about controllers.
在这里看到: DEMO
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>
这篇关于表单元素没有出现在$范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文