【发布时间】:2016-03-11 07:17:06
【问题描述】:
我有一个使用 AngularJS 的 ASP.NET MVC5 应用程序。在此,我有一个名为 atTheMS 的模块和一个名为 albumService 的服务工厂和 3 个控制器:ListController、EditController 和 DetailsController。服务和控制器都依赖于atTheMS 模块,但我只从albumService 得到这个错误
Uncaught Error: [$injector:nomod] Module 'atTheMS' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
它说它发生在(anonymous function) albumService.js:27
(function (app) {
var albumService = function ($http, albumApiUrl) {
var getAll = function () {
return $http.get(albumApiUrl);
};
var getById = function (id) {
return $http.get(albumApiUrl + id);
};
var update = function (album) {
return $http.put(albumApiUrl + album.Id, album);
};
var create = function (album) {
return $http.post(albumApiUrl, album);
};
var destroy = function (album) {
return $http.delete(albumApiUrl + album.Id);
};
return {
getAll: getAll,
getById: getById,
update: update,
create: create,
delete: destroy
};
};
app.factory("albumService", albumService);
}(angular.module("atTheMS")));
使用(angular.module("atTheMS")) 的其他文件不会出现该错误,这是复制我拥有的另一个工厂而生成的,除了单词“album”被单词“book”替换并且模块是“ atTheLibrary”,当我在该页面上时没有错误。我很困惑为什么这会有所不同。任何帮助将不胜感激,谢谢。
根据要求,这是视图:
@section scripts {
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-route.js"></script>
<script src="~/Client/Scripts/Album/albumService.js"></script>
<script src="~/Client/Scripts/Album/atTheMS.js"></script>
<script src="~/Client/Scripts/Album/ListController.js"></script>
<script src="~/Client/Scripts/Album/DetailsController.js"></script>
<script src="~/Client/Scripts/Album/EditController.js"></script>
}
<div data-ng-app="atTheMS">
<ng-view></ng-view>
</div>
<hr />
【问题讨论】:
-
你能发布你的 HTML 吗?
-
@Oleander 在编辑中发布,谢谢。
-
不应该是
angular.module("atTheMS", [])btw吗? -
不..他已经在 atTheMS.js 中创建了模块
-
在服务可以使用该模块之前应该加载该模块。 'atTheMS.js' 文件应该在 'albumService.js' 之前加载
标签: javascript angularjs asp.net-mvc-5 factory angular-module