【发布时间】:2015-01-30 18:43:42
【问题描述】:
我是 Angular 新手,我有一个问题。
我使用的是 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>
提前谢谢你。
【问题讨论】:
-
好吧,新的角度 - 试试这个docs.angularjs.org/tutorial。您的 sn-p 缺少角度基础知识...教程应该有所帮助
-
我不知道问题是什么,但想说不要在 html 中的赋值之间放置空格,如下所示:
ng-controller = "MyController"应该是ng-controller="MyController" -
@RadimKöhler OP 在头部包含了角度...
-
docs.angularjs.org/guide/migration 从 1.2 迁移到 1.3 $controller 将不再在窗口上寻找控制器。使用 angular.module('myApp', []).controller('MyController', [function() { // ... }]);
标签: javascript html angularjs