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

      

  • 相关阅读:
    [LeetCode] 500. Keyboard Row 键盘行
    [LeetCode] 502. IPO 上市
    [LeetCode] 495. Teemo Attacking 提莫攻击
    [LeetCode] 655. Print Binary Tree 打印二叉树
    [LeetCode] 654. Maximum Binary Tree 最大二叉树
    [LeetCode] 637. Average of Levels in Binary Tree 二叉树的层平均值
    Dubbo 在maven项目中的应用
    前后端分离springmvc和RESTful理解
    一个相对通用的JSON响应结构,其中包含两部分:元数据与返回值
    MAC OS查看端口占用情况及杀死进程
  • 原文地址:https://www.cnblogs.com/myzy/p/5984297.html
Copyright © 2020-2023  润新知