這似乎是很簡單,但不工作:由布拉德·格林的書「AngularJS」第一個例子有錯誤
<html ng-app>
<head>
<script type="text/javascript" src="lib/angular.js"></script>
<script type="text/javascript">
function HelloController($scope) {
$scope.greeting = { text: 'Hello' };
}
</script>
</head>
<body>
<div ng-controller='HelloController'>
<p>{{greeting.text}}, World</p>
</div>
</body>
</html>
在屏幕上:
{{greeting.text}}, World
,並在控制檯:
Error: [ng:areq] Argument 'HelloController' is not a function, got undefined
http://errors.angularjs.org/1.3.0/ng/areq?p0=HelloController&p1=not%20a%20function%2C%20got%20undefined
at http://localhost:8080/lib/angular.js:80:12
at assertArg (http://localhost:8080/lib/angular.js:1610:11)
at assertArgFn (http://localhost:8080/lib/angular.js:1620:3)
at http://localhost:8080/lib/angular.js:8319:9
at http://localhost:8080/lib/angular.js:7496:34
at forEach (http://localhost:8080/lib/angular.js:343:20)
at nodeLinkFn (http://localhost:8080/lib/angular.js:7483:11)
at compositeLinkFn (http://localhost:8080/lib/angular.js:6991:13)
at compositeLinkFn (http://localhost:8080/lib/angular.js:6994:13)
at compositeLinkFn (http://localhost:8080/lib/angular.js:6994:13)
看不到原因......除了可能是因爲我用AngularJS v1.3.0
?
不確定關於v1.3.0,但[它適用於v1.2.1](http://jsfiddle.net/rdesai/7rakjukj/)。 [FYI,v1.3.0被列爲不穩定](https://developers.google.com/speed/libraries/devguide?hl=fr#angularjs)。 – 2014-10-20 05:41:24