当学习angularjs 遇到
Error: [ng:areq] Argument 'HelloController' is not a function, got undefined
http://errors.angularjs.org/1.3.15/ng/areq?p0=HelloController&p1=not%20a%20function%2C%20got%20undefined
minErr/<@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:63:12
assertArg@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:1587:1
assertArgFn@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:1597:1
$ControllerProvider/this.$get</<@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:8470:9
nodeLinkFn/<@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:7638:34
forEach@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:331:11
nodeLinkFn@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:7625:11
compositeLinkFn@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:7117:13
compositeLinkFn@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:7120:13
compositeLinkFn@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:7120:13
publicLinkFn@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:6996:30
bootstrapApply/<@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:1457:11
$RootScopeProvider/this.$get</Scope.prototype.$eval@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:14466:16
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:14565:18
bootstrapApply@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:1455:9
invoke@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:4203:14
bootstrap/doBootstrap@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:1453:1
bootstrap@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:1473:1
angularInit@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:1367:5
@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:26304:5
trigger@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:2762:7
createEventHandler/eventHandler@http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js:3032:9
http://special.csc86.com/peng/AngularJS/js/angular-1.3.15/angular.js
Line 11655
如下图:
出现这种问题的原因:
出现这个问题是因为在 angularJs 1.3 中 为了让 根节点上(rootScope)不再被挂上许多冗余的内容,所以禁止了直接在根上注册controller(即在全局作用域中创建控制器)。故下面这种写法会报上面的错误:
解决方法:
第一:以后不能直接以 function XXXController ($scope){ code......}这样的方式直接注册监听器了。以后必须
angular.module('hello', []).controller('HelloController',function($scope) {})这样来将controller注册到对应的模型上。
第二: 在 ng-aap 中指定相对应的模型。
如 之前:
<html ng-app>(不指定则为根元素)
现在:
<html ng-app="hello">
下面为修改并整理后不会报错的代码: