• angular报错:angular.min.js:118Error: [ng:areq] http://errors.angularjs.org/1.5.8/ng/areq


    报错代码如下:

        <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>
    

      

  • 相关阅读:
    MySql的约束
    这个充满恶意的世界啊,一不小心就掉里
    hack
    jQuery.rotate.js参数
    代码在ie9中不能正确执行
    ie6,ie7,ie8 css bug兼容解决方法
    常用CSS缩写语法总结
    前端CSS规范整理_转载、、、
    JS定义数组,初始化
    php js数组问题
  • 原文地址:https://www.cnblogs.com/myzy/p/5984297.html
Copyright © 2020-2023  润新知