【发布时间】:2015-07-28 01:41:57
【问题描述】:
当我尝试运行下面的代码时,我收到两个错误提示
错误:[$injector:nomod] 模块“房间”不可用!你要么 模块名称拼写错误或忘记加载它。如果注册一个 模块确保您将依赖项指定为第二个 论据。
错误:[$injector:modulerr] 无法实例化 模块应用程序由于:[$injector:nomod] 模块“应用程序”不可用! 您要么拼错了模块名称,要么忘记加载它。如果 注册模块确保将依赖项指定为 第二个参数。
我可以看到我没有在任何地方拼错模块的名称,并且我已经包含了必要模块的依赖项,并且我已经按照必要的顺序构建了模块,因此没有一个模块是相互未定义的(如 rooms.controllers 模块在注入之前存在,而 rooms 模块在注入应用模块之前存在
(function(){
'use strict';
//create the module that is going to contain the controllers for the rooms module
angular.module('rooms.controllers', [])
.controller('RoomCtrl', RoomCtrl);
function RoomCtrl(){
var vm = this;
vm.rooms = [];
};
})();
(function(){
'use strict';
//create the rooms module and inject rooms.controllers module and ngRoute module
angular
.module('rooms', ['rooms.controllers', 'ngRoute']);
});
(function(){
'use strict';
//get the rooms module and config it's routes, because we're getting it we don't need []
angular
.module('rooms')
.config(function($routeProvider){
$routeProvider
.when('/rooms',{
templateUrl:'public/modules/rooms/templates/roomlist.html',
controller: 'RoomCtrl',
controllerAs: 'room'
})
})
})();
(function(){
'use strict';
//bootstrap the whole thing together
angular.module('app', ['rooms']);
})();
【问题讨论】:
标签: javascript angularjs