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 beng-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
2 Answers
Reset to default 7There 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
版权声明:本文标题:javascript - Angular JS 1.3.11: Argument 'MyController' is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744859798a2629000.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论