报错代码如下:

 

1
2
3
4
5
6
7
8
9
    <div ng-controller="HelloAngular">
        <p>{{greeting.text}},angular</p>
    </div>
 
function HelloAngular($scope){
    $scope.greeting = {
        text:'hello'
    }
}

 在用angular1.3版本以前的时候,上面的代码运行是没有问题的。但是我更新版本后报错

1
2
3
4
5
6
7
8
9
10
11
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数据

修改后的代码

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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>

  

posted on   坚持不懈❥  阅读(592)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示