簡體   English   中英

即使定義了角度模塊也不可用

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

當我嘗試運行下面的代碼時,出現兩個錯誤:

錯誤:[$ injector:nomod]模塊“房間”不可用! 您可能拼錯了模塊名稱,或者忘記了加載它。 如果注冊模塊,請確保將依賴項指定為第二個參數。

錯誤:[$ injector:modulerr]由於以下原因而無法實例化模塊應用程序:[$ injector:nomod]模塊'app'不可用! 您可能拼錯了模塊名稱,或者忘記了加載它。 如果注冊模塊,請確保將依賴項指定為第二個參數。

我可以看到我在任何地方都沒有拼寫錯誤的模塊名稱,並且包含了必要模塊的依賴關系,並且按照必要的順序對模塊進行了結構化,這樣就不會為彼此定義模塊了(如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']);

})();

該代碼塊不執行。

(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