angularjs模块依赖 [英] angularjs module dependencies
问题描述
我定义我的主要模块,例如:
I've defined my main module as such:
angular.module('domiciliations', ['domiciliations.service', 'loggerService', 'person.directives']).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/domiciliations/mandats', { templateUrl: 'domiciliations/views/mandats.html', controller: mandatsCtrl }).
when('/domiciliations/mandats/:rum', { templateUrl: 'domiciliations/views/mandat.html', controller: mandatCtrl }).
otherwise({ redirectTo: '/domiciliations/mandats' });
}]).
value('toastr', window.toastr).
value('breeze', window.breeze);
我的问题是怎么样怎么样在我的控制器指定模块依赖?
My problem is how to how specify module dependencies in my controller?
如果我做的:
angular.module('domiciliations.service', ['ngResource', 'breeze', 'loggerService']).
factory('Domiciliation', function ($resource, breeze, logger) {
}
然后,我得到一个错误。没有模块:清风
Then I get an error 'no module: breeze'.
它的工作原理,如果我做的:
It works if I do:
angular.module('domiciliations.service', ['ngResource']).
factory('Domiciliation', function ($resource, breeze, logger) {
}
所以,我怎么想指定的微风和记录器的依赖?
So how am I suppose to specify dependencies on breeze and logger?
推荐答案
微风
不是一个模块 - 这是一个值(速记服务)中的 domiciliations
模块中:值('清风',window.breeze);
。
breeze
is not a module - it's a value (shorthand for service) in the domiciliations
module: value('breeze', window.breeze);
.
当你这样做:
angular.module('domiciliations.service', ['ngResource', 'breeze', 'loggerService']).
factory('Domiciliation', function ($resource, breeze, logger) {
}
您配置 domiciliations.service
的模块的具有相关性的模块 ngResource
, 微风
和 loggerService
。角找不到微风
的模块的并且抛出异常。
You configure the domiciliations.service
module with dependencies to the modules ngResource
, breeze
and loggerService
. Angular can't find the breeze
module and throws an exception.
假设 loggerService
是一个模块,记录
是这样的模块中的服务,下面应该工作(微风
和记录
将在工厂函数获得注入):
Assuming loggerService
is a module and logger
is a service in this module, the following should work (breeze
and logger
will get injected in the factory function):
angular.module('domiciliations.service', ['ngResource','loggerService']).
factory('Domiciliation', ['$resource','breeze','logger',
function ($resource, breeze, logger) {
}
])
这篇关于angularjs模块依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!