Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular JS 1.3.11: Argument 'MyController' is not a function

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

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

</body>
</html>

Thank you in advance.

like image 588
Naim Avatar asked Feb 11 '23 01:02

Naim


1 Answers

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

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

like image 110
Radim Köhler Avatar answered Feb 13 '23 15:02

Radim Köhler