我是一名初学程序员,学习角度并跟随音乐商店应用程序。我在angularJS中显示一条消息时遇到了一些麻烦,并且想知道它是否是代码中的问题,或其他什么。我的预期结果是简单地显示" Manish Kumar"在页面上。但是,我的实际结果只是显示html中的{{message}}。好像它没有拿起JS控制器参考。请注意这个例子是在VS 2013中完成的,而我使用的是2015年。感谢任何帮助,因为我是初学者。谢谢!!
我的代码&文件:
索引HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="../../Scripts/angular.js"></script>
<script src="../Scripts/theMusic.js"></script>
<script src="../Scripts/MusicListController.js"></script>
</head>
<body>
<div ng-app="theMusic">
<div ng-controller="MusicListController">
{{message}}
</div>
</div>
</body>
</html>
MusicListController:
(function (app) {
var MusicListController = function ($scope) {
$scope.message = "Manish Kumar";
};
app.controller("MusicListController", MusicListController);
}(Angular.module("theMusic")));
theMusic Class:
(function () {
var app = Angular.module("theMusic", []);
}());
答案 0 :(得分:1)
请尝试这种类型我认为解决您的问题只是做一些改变。
(function () {
var app = angular.module("theMusic", []);
}());
(function (app) {
var MusicListController = function ($scope) {
$scope.message = "Manish Kumar";
};
app.controller("MusicListController", MusicListController);
}(angular.module("theMusic")));
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="../../Scripts/angular.js"></script>
<script src="../Scripts/theMusic.js"></script>
<script src="../Scripts/MusicListController.js"></script>
</head>
<body>
<div ng-app="theMusic">
<div ng-controller="MusicListController">
{{message}}
</div>
</div>
</body>
</html>
&#13;