简体   繁体   English

即使定义了角度模块也不可用

[英]angular module not available even though it's defined

When I try to run the code below I get two errors that say 当我尝试运行下面的代码时,出现两个错误:

Error: [$injector:nomod] Module 'rooms' is not available! 错误:[$ injector:nomod]模块“房间”不可用! 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. 如果注册模块,请确保将依赖项指定为第二个参数。

Error: [$injector:modulerr] Failed to instantiate module app due to: [$injector:nomod] Module 'app' is not available! 错误:[$ injector:modulerr]由于以下原因而无法实例化模块应用程序:[$ injector:nomod]模块'app'不可用! 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. 如果注册模块,请确保将依赖项指定为第二个参数。

I can see that I haven't misspelled the the name of the module anywhere and I have included the dependencies for the necessary modules and I have structured the modules in the necessary order so that none of the modules are undefined for each other(as in rooms.controllers module exists before it's injected and rooms module exists before it's injected into the app module 我可以看到我在任何地方都没有拼写错误的模块名称,并且包含了必要模块的依赖关系,并且按照必要的顺序对模块进行了结构化,这样就不会为彼此定义模块了(如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']);

})();

This code block is not executed. 该代码块不执行。

(function(){
    'use strict';
    //create the rooms module and inject rooms.controllers module and ngRoute module
    angular.module('rooms', ['rooms.controllers', 'ngRoute']);
})(); // <-- here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM