Angular JS 1.3.11:Argument' MyController'不是一个功能

时间:2015-01-30 18:43:43

标签: javascript html angularjs

我是棱角分明的新人,我有一个问题。

我正在使用1.3.11版本的角度。

我写了一个简单的html代码,使用简单的角度和我得到以下错误:

  

Argument' MyController'不是函数,在AngularJS中没有定义[重复]

html代码是:

<!DOCTYPE html>
<html 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> {{author.name}}</h1>
  <p> {{author.title + ', ' + author.company}}</p>
</div>

<script>
  function MyController($scope)
  {
    $scope.author= {
      'name' : 'Naim',
      'title' : 'MR',
      'company' : 'Naimos'
    }
  }
</script>

</body>
</html>

提前谢谢。

2 个答案:

答案 0 :(得分:7)

working plunker

<!DOCTYPE html>
<html ng-app="app">

  <head>
    <meta charset="UTF-8" />
    <title>Angular Demo</title>
    <script data-require="angular.js@*" data-semver="1.3.11" 
     src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.11/angular.js"
    ></script>
  </head>

  <body>
    <div ng-controller="MyController">
      <h1> {{author.name}}</h1>
      <p> {{author.title + ', ' + author.company}}</p>
    </div>
    <script>
  function MyController($scope)
  {
    $scope.author= {
      'name' : 'Naim',
      'title' : 'MR',
      'company' : 'Naimos'
    }
  }
  angular
    .module('app', [])
    .controller("MyController", MyController)
    </script>
  </body>

</html>

检查角度模块的定义:

  angular
    .module('app', [])
    .controller("MyController", MyController)

而且,模块“app”现在注入了html

<html ng-app="app">

检查行动here

答案 1 :(得分:1)

适用于SO?!

这是引用1.2

按照迁移示例来使用1.3

https://docs.angularjs.org/guide/migration

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html 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> {{author.name}}</h1>
  <p> {{author.title + ', ' + author.company}}</p>
</div>

<script>
  function MyController($scope)
  {
    $scope.author= {
      'name' : 'Naim',
      'title' : 'MR',
      'company' : 'Naimos'
    }
  }
</script>

</body>
</html>
&#13;
&#13;
&#13;