代码在这里:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body ng-app="app">
<p ng-controller="MessageController">
{{message}}
</p>
<script src="../../angularv1.min.js"></script>
<script src="message-controller-scope.js"></script>
</body>
</html>
/**
* Created by Glacier on 2015/7/19.
message-controller-scope.js
*/
function MessageController($scope) {
$scope.message = "This is a model.";
}
结果是{{message}} 为什么不显示这是一个型号? 有什么不对吗?
这是一个角度控制器范围问题。
答案 0 :(得分:0)
您需要创建角度模块:
angular.module('app')
.controller('MessageController', MessageController);
function MessageController($scope) {
$scope.message = "This is a model.";
}
MessageController.$inject = ['$scope'];
答案 1 :(得分:0)
var app = angular.module('app',[]);
app.controller('MessageController', ['$scope', function($scope) {
$scope.message = "This is a model.";
}]);