2014-10-19 98 views
0

我無法弄清楚我在這裏做錯了什麼。未能實例化模塊maq

//app.js 

'use strict'; 

var app = angular.module('maq', [ 
    'ui.router', 
    'maq.home.controller' 
]).run([ 
    '$rootScope', 
    '$state', 
    '$stateParams', function($rootScope, $state, $stateParams){ 
     $rootScope.$state = $state; 
     $rootScope.$stateParams = $stateParams; 
    }]) 
    .config([ 
    '$stateProvider', 
    '$urlRouterProvider', function($stateProvider, $urlRouterProvider){ 

     $urlRouterProvider.otherwise('/'); 

     $stateProvider 
     .state('home', { 
      url: '/', 
      templateUrl: 'views/home.html', 
      controller: 'maq.home.controller' 
     }) 
    }]); 

//controller 
'use strict'; 

app 
    .controller('maq.home.controller', [function(){ 

    }]); 


//error 
Uncaught Error: [$injector:modulerr] Failed to instantiate module maq due to: 
Error: [$injector:modulerr] Failed to instantiate module maq.home.controller due to: 
Error: [$injector:nomod] Module 'maq.home.controller' 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. 

回答

1

你居然沒有一個叫maq.home.controller相反模塊的註冊是在這樣一種方式,它是控制器的名字。

如果你想你的控制器分離到另一個模塊(如你正在嘗試做的)

嘗試: -

angular.module('maq.controller', []); //<-- Module creation 
//... 
angular.module('maq.controller') 
     .controller('HomeController', [function() { //<-- Controller registration 

}]); 

,並在您的應用程序: -

var app = angular.module('maq', [ 
    'ui.router', 
    'maq.controller' //<-- Controller mmodule 
]); 

或者只是刪除不存在的模塊依賴關係: -

angular.module('maq', [ 
    'ui.router', 
    //'maq.home.controller' <-- Remove this 
]) 
+0

謝謝,那是我的問題。 – chovy 2014-10-19 03:51:22

+0

@chovy歡迎你 – PSL 2014-10-19 03:53:42

+0

@chovy你介意接受答案嗎?謝謝! :) – PSL 2014-10-20 11:26:50

0

您試圖依賴於另一個模塊命名maq.home.controller當它不是一個模塊,它是一個控制器。您不需要在模塊聲明中將控制器列爲依賴項。所以,就把這種依賴了,像這樣:

var app = angular.module('maq', [ 
    'ui.router' 
]) 
相關問題