我是角度新手,我有一个问题。
我使用 1.3.11 版本的 Angular。
我写了一个简单的 html 代码,使用简单的角度,但出现以下错误:
参数“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>
先感谢您。
有工作笨蛋 http://plnkr.co/edit/Gs4PaFmqYRZ14N1i1XhP?p=preview
<!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 http://plnkr.co/edit/Gs4PaFmqYRZ14N1i1XhP?p=preview
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)