首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >引导后从非angularAMD模块加载工厂

引导后从非angularAMD模块加载工厂
EN

Stack Overflow用户
提问于 2014-04-09 05:10:18
回答 1查看 472关注 0票数 0

在这个柱塞器(http://plnkr.co/edit/IpewSU)中,我创建了一个在模块'webapp‘中注册的工厂'LoggerFactory’。工厂在控制器'logCtrl‘中使用。如果路由是'/log‘,则在bootstrap之后加载此控制器get。有一个模块“LoggerModule”,并且LoggerFactory应该属于此模块,而不是“webapp”。

当我在引导之前加载工厂时(例如,在‘webapp’中添加依赖项),我可以在该模块中创建工厂。Plunker:http://plnkr.co/edit/Fn6rxg

但是在使用它之前加载工厂对于大型应用程序来说不是一个解决方案...

我错过了什么?是否每个工厂都需要在其中创建自己的模块,以及何时:如何将此模块注入到另一个已引导的模块中?

EN

回答 1

Stack Overflow用户

发布于 2014-04-09 22:47:44

目前,我使用此解决方案将元素注册到angularAMD应用程序中的外部模块:

代码语言:javascript
复制
// 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);
            }
        }
    }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22948245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档