使用中遇到的問題:
1.{{}}取值無效,控制檯輸出ng-controller指向的函數名is not a function:
a). 查看elements,dom元素上有class=”ng-scope”,判斷angular.js引入正常。
b). 控制檯輸入ng-controller指向的函數名,該函數也存在。
c). 最後查詢結果爲angularJS自1.3.0之後不支持全局函數作爲ng-controller.只能使用模塊化的方式定義controller。
HelloAngular_MVC.js:
var myModule = angular.module("HelloAngular",[]);
myModule.controller('helloAngular',['$scope',
function HelloAngular($scope){
$scope.greeting = {
text: 'Hello'
};
}
]);
index.html:(還需引入angularJS文件)
<!DOCTYPE html>
<html ng-app="HelloAngular">
<head lang="en">
<meta charset="UTF-8">
<title>Hello AngularJS</title>
</head>
<body>
<div ng-controller="helloAngular">
<p>{{greeting.text}},Angular</p>
</div>
</body>
<script src="lib/angular.js"></script>
<script src="js/HelloAngular_MVC.js"></script>
</html>