【发布时间】:2013-08-01 12:06:55
【问题描述】:
我正在学习 AngularJS,并试图做以下基本的事情:
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js" type="text/javascript"></script>
<script type="text/javascript">
var myapp = angular.module('MyTutorialApp',[]);
myapp.controller("MyMainController", function($scope){
$scope.understand = "I now understand how the scope works2!";
});
</script>
</head>
<body ng-app='MyTutorialApp'>
<div id='content' ng-controller='MyMainController'>
{{understand}}
</div>
</body>
</html>
但上面的代码出现错误,错误提示“错误:参数 'MyMainController' 不是函数,未定义”
但如果我改用下一个代码,应用程序就可以工作
function MyMainController($scope) {
$scope.understand = 'I now understand how the scope works3';
}
【问题讨论】:
标签: angularjs