在这个柱塞器(http://plnkr.co/edit/IpewSU)中,我创建了一个在模块'webapp‘中注册的工厂'LoggerFactory’。工厂在控制器'logCtrl‘中使用。如果路由是'/log‘,则在bootstrap之后加载此控制器get。有一个模块“LoggerModule”,并且LoggerFactory应该属于此模块,而不是“webapp”。
当我在引导之前加载工厂时(例如,在‘webapp’中添加依赖项),我可以在该模块中创建工厂。Plunker:http://plnkr.co/edit/Fn6rxg
但是在使用它之前加载工厂对于大型应用程序来说不是一个解决方案...
我错过了什么?是否每个工厂都需要在其中创建自己的模块,以及何时:如何将此模块注入到另一个已引导的模块中?
发布于 2014-04-09 22:47:44
目前,我使用此解决方案将元素注册到angularAMD应用程序中的外部模块:
// bind submodules to register their functions here
app.run(function() {
var bindRegister = function(module, type) {
return function() {
module.register[type].apply(null, arguments);
return module['_'+type].apply(null, arguments);
};
};
var t, type, types = ['controller','factory','directive','filter','service','constant','value','animation'];
var m, module, modules = ['AccountModule', 'NoticeModule'];
for (m in modules) {
module = angular.module(modules[m]);
module.register = app.register;
for (t in types) {
type = types[t];
if (typeof(module[type]) == 'function') {
module['_'+type] = module[type];
delete module[type];
module[type] = bindRegister(module, type);
}
}
}
});https://stackoverflow.com/questions/22948245
复制相似问题