<!DOCTYPE html>
<html lang="en" ng-app>
<head>
<meta charset="UTF-8">
<title>Simple angular</title>
<script src="lib/angular/angular.min.js"></script>
</head>
<body>
<div ng-controller="MyController">
<h1>{{a.name}}</h1>
</div>
<script>
function MyController($scope) {
$scope.a = {
'name':"fox",
'title':'hello'
}
}
</script>
</body>
</html>
答案 0 :(得分:5)
由于您正在使用Angular 1.3,因此您需要&#34;附加&#34;你的控制器到你的模块:
<!DOCTYPE html>
<html lang="en" ng-app="myApp"> //Change #1: need to write your app here
<head>
<meta charset="UTF-8">
<title>Simple angular</title>
<script src="lib/angular/angular.min.js"></script>
</head>
<body>
<div ng-controller="MyController">
<h1>{{a.name}}</h1>
</div>
<script>
var app = angular.module("myApp", []); //Change #2: declare your app
function MyController($scope) {
$scope.a = {
'name':"fox",
'title':'hello'
}
}
app.controller("MyController", MyController); //Change #3: attach your controller
</script>
</body>
</html>
您的代码需要进行3次调整。