报错代码如下:
<div ng-controller="HelloAngular">
<p>{{greeting.text}},angular</p>
</div>
function HelloAngular($scope){
$scope.greeting = {
text:'hello'
}
}
在用angular1.3版本以前的时候,上面的代码运行是没有问题的。但是我更新版本后报错
Error: [ng:areq] http://errors.angularjs.org/1.5.8/ng/areq?p0=*&p1=not%20a%20function%2C%20got%20undefined
at Error (native)
at http://localhost:63342/untitled1/public/javascripts/lib/angular.min.js:6:412
at sb (http://localhost:63342/untitled1/public/javascripts/lib/angular.min.js:23:18)
at Pa (http://localhost:63342/untitled1/public/javascripts/lib/angular.min.js:23:105)
at http://localhost:63342/untitled1/public/javascripts/lib/angular.min.js:89:310
at ag (http://localhost:63342/untitled1/public/javascripts/lib/angular.min.js:72:419)
at p (http://localhost:63342/untitled1/public/javascripts/lib/angular.min.js:64:262)
at g (http://localhost:63342/untitled1/public/javascripts/lib/angular.min.js:58:481)
at g (http://localhost:63342/untitled1/public/javascripts/lib/angular.min.js:58:498)
at g (http://localhost:63342/untitled1/public/javascripts/lib/angular.min.js:58:498)
因为不允许定义全局函数来污染全局对象,做好放在module.controller()这样一个函数中来操作model数据
修改后的代码
mvc.js
var app = angular.module('userApp',[]);
app.controller('HelloAngular',function($scope){
$scope.greeting = {
text:'hello'
}
})
<!doctype html>
<html ng-app="userApp">
<head>
<meta charset="utf-8">
</head>
<body>
<div>
<div ng-controller="HelloAngular">
<p>{{greeting.text}},angular</p>
</div>
</div>
</body>
<script src="../public/javascripts/lib/angular.min.js"></script>
<script src="../public/javascripts/test/mvc.js"></script>
</html>
浙公网安备 33010602011771号