简体   繁体   English

角度js-错误:ng:areq错误参数-

[英]Angular js- Error: ng:areq Bad Argument-

I saw the there are several question regarding this error, but I didn't find the answer for my case. 我看到有关此错误的几个问题,但我没有找到适合我的情况的答案。

I am new to angular and started to build small app. 我是新手,因此开始构建小型应用程序。

<!doctype html>
<html lang="en" ng-app>
<head>
  <meta charset="UTF-8">
  <title>Angular Demo</title>
  <script src="lib/angular/angular.min.js"></script>


</head>
<body>
<div ng-controller =" MyController">
  <h1>{{player.name}}</h1>
</div>
<script>
  function MyController($scope) {
    $scope.player = {
      'name': 'Eran Zahavi',
      'number': '7',
      'position': 'link'
    }
  }
</script>
</body>
</html>

When I tried to run it I got the error above--> Error: [ng:areq] http://errors.angularjs.org/1.4.3/ng/areq?p0=MyController&p1=not%20a%20function%2C%20got%20undefined 当我尝试运行它时,出现上面的错误->错误:[ng:areq] http://errors.angularjs.org/1.4.3/ng/areq?p0=MyController&p1=not%20a%20function%2C %20got%20undefined

If you are refering to angular above 1.3 version, you should declare controller different way, 如果您是指1.3以上版本的Angle,则应以其他方式声明控制器,

var newApp = angular.module('newApp', []);
newApp.controller('MyController', function($scope){

   $scope.player = {
      'name': 'Eran Zahavi',
      'number': '7',
      'position': 'link'
   }
});

Here is the Plunker 这是Plunker

From angular 1.4.x you can't define controller globally. 从angular 1.4.x开始,您无法全局定义控制器。

You have to declare controller inside module. 您必须在模块内部声明控制器。

Like this 像这样

<!doctype html>
<html lang="en" ng-app="app">

    <head>
        <meta charset="UTF-8">
        <title>Angular Demo</title>
        <script src="lib/angular/angular.min.js"></script>
    </head>

    <body>
        <div ng-controller=" MyController">
             <h1>{{player.name}}</h1>

        </div>
        <script>
            var app = angular.module("app", []);
            app.controller("MyController", function($scope) {
                $scope.player = {
                    'name': 'Eran Zahavi',
                        'number': '7',
                        'position': 'link'
                }
            });
        </script>
    </body>

</html>

JSFIDDLE JSFIDDLE

Can you please try this . 你能试试这个吗?

<body ng-app="">
<div ng-controller ="MyController">
  <h1>{{player.name}}</h1>
</div>
<script>
  function MyController($scope) {
    $scope.player = {
      'name': 'Eran Zahavi',
      'number': '7',
      'position': 'link'
    }
  }
</script>
</body>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular JS错误:错误:areq Bad Argument - Angular JS Error: error:areq Bad Argument Angular JS和TypeScript-错误:ng:areq错误参数“参数&#39;XXXXXX&#39;不是函数,未定义” - Angular JS & TypeScript - Error: ng:areq Bad Argument “Argument 'XXXXXX' is not a function, got undefined” Angular JS-错误:ng:areq错误的参数参数&#39;GameContoller&#39;不是函数,未定义 - Angular JS - Error: ng:areq Bad Argument Argument 'GameContoller' is not a function, got undefined AngularJS-为什么“错误:ng:areq错误参数”? - AngularJS - why “Error: ng:areq Bad Argument”? 错误:ng:areq错误参数AngularJS - Error: ng:areq Bad Argument AngularJS 角:由于缩小而导致“错误:areq错误参数”? - Angular: 'error:areq Bad Argument' due to minification? 错误:ng:areq错误的参数和参数未在ANGULARJS中定义 - Error: ng:areq Bad Argument and argument not defined in ANGULARJS 错误:ng:areq错误参数:参数&#39;registerController&#39;不是函数,未定义 - Error: ng:areq Bad Argument: Argument 'registerController' is not a function, got undefined AngularJS错误:ng:使用控制器时areq Bad Argument - AngularJS Error: ng:areq Bad Argument while using controller Angular“angular.js:14110错误:[ng:areq]参数&#39;fn&#39;不是函数,未定义”控制器实例化异常 - Angular “angular.js:14110 Error: [ng:areq] Argument 'fn' is not a function, got undefined” exception on controller instantiation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM