2014-10-19 95 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' 
]) 
相关问题