當學習angularjs 遇到html
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 11655node
以下圖:angularjs
出現這種問題的緣由:bootstrap
出現這個問題是由於在 angularJs 1.3 中 爲了讓 根節點上(rootScope)再也不被掛上許多冗餘的內容,因此禁止了直接在根上註冊controller(即在全局做用域中建立控制器)。故下面這種寫法會報上面的錯誤:app
解決方法:ide
第一:之後不能直接以 function XXXController ($scope){ code......}這樣的方式直接註冊監聽器了。之後必須學習
angular.module('hello', []).controller('HelloController',function($scope) {})這樣來將controller註冊到對應的模型上。this
第二: 在 ng-aap 中指定相對應的模型。prototype
如 以前:3d
<html ng-app>(不指定則爲根元素)
如今:
<html ng-app="hello">
下面爲修改並整理後不會報錯的代碼: