admin管理员组

文章数量:1404927

I'm new to angular and i have a question.

Im using 1.3.11 version of angular.

Ive wrote a simple html code that that using simple angular and im getting the following error:

Argument 'MyController' is not a function, got undefined in AngularJS [duplicate]

the html code is:

<!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 + ', ' + authorpany}}</p>
</div>

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

</body>
</html>

Thank you in advance.

I'm new to angular and i have a question.

Im using 1.3.11 version of angular.

Ive wrote a simple html code that that using simple angular and im getting the following error:

Argument 'MyController' is not a function, got undefined in AngularJS [duplicate]

the html code is:

<!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.pany}}</p>
</div>

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

</body>
</html>

Thank you in advance.

Share Improve this question asked Jan 30, 2015 at 18:43 NaimNaim 558 bronze badges 4
  • 2 Well, new in angular - try this docs.angularjs/tutorial. Your snippet is missing angular basics... tutorial should help – Radim Köhler Commented Jan 30, 2015 at 18:45
  • I don't know what's the probelme but would like to say don't put space between assignment in html like here: ng-controller = "MyController" should be ng-controller="MyController" – Bhojendra Rauniyar Commented Jan 30, 2015 at 18:45
  • @RadimKöhler OP has included angular in head... – Bhojendra Rauniyar Commented Jan 30, 2015 at 18:46
  • 1 docs.angularjs/guide/migration Migrating from 1.2 to 1.3 $controller will no longer look for controllers on window .Use angular.module('myApp', []).controller('MyController', [function() { // ... }]); – micha Commented Jan 30, 2015 at 19:17
Add a ment  | 

2 Answers 2

Reset to default 7

There is 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./ajax/libs/angular.js/1.3.11/angular.js"
    ></script>
  </head>

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

</html>

Check the definition of the angular module:

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

And also, the module "app" is now injected int html

<html ng-app="app">

Check it in action here

works on SO?!

this is referencing 1.2

follow the migration example to get ti working with 1.3

https://docs.angularjs/guide/migration

<script src="https://ajax.googleapis./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.pany}}</p>
</div>

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

</body>
</html>

本文标签: javascriptAngular JS 1311 Argument 39MyController39 is not a functionStack Overflow