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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With