angular.bootstrap后角添加模块 [英] Angular add modules after angular.bootstrap

查看:157
本文介绍了angular.bootstrap后角添加模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用流星+棱角分明。我的目的是引导程序后,添加更多的依赖(这是因为包是一个处理在开始的引导,我不拥有它的控制权)。现在,而这样做,我也想强制实施基本code结构,其中,例如,我会编译所有控制器在一个模块中

I'm using meteor + angular. My intention is to add more dependencies after the app bootstrap (This is because the package is the one handling the bootstrapping at the start and I don't have much control of it). Now while doing that, I would also want to enforce a basic code structure wherein for example, I would compile all controllers in one module.

这里的基本思想是:

'use strict';

angular.module('app.controllers', [])

    .controller('MainCtrl', function() {
        // ...
    })

    .controller('SubCtrl', function() {
        // ...
    })

    .controller('AnotherCtrl', function() {
        // ...
    });

接着包括向主模块依赖关系:

Then include that to the main module as dependency:

angular.module('app', [
    'app.filters',
    'app.services',
    'app.directives',
    'app.controllers' // Here
]);

经过一番研究,我发现,我想要做的(引导后添加依赖)实际上是一个功能要求的角度团队的一部分。所以我的选择是使用,例如, $ controllerProvider 寄存器()功能:

Meteor.config(function($controllerProvider) {
    $controllerProvider.register('MainCtrl', function($scope) {
        // ...
    });
});

Meteor.config(function($controllerProvider) {
    $controllerProvider.register('SubCtrl', function($scope) {
        // ...
    });
});

Meteor.config(function($controllerProvider) {
    $controllerProvider.register('AnotherCtrl', function($scope) {
        // ...
    });
});

它的作品,虽然没有那么优雅。这些问题是:

It's works though not that elegant. The questions are:


  • 什么是做的更优雅的方式在配置注册部分?

  • 有没有注册的模块,而不是方法?

推荐答案

创建你的模块:

angular.module('app.controllers', []);

其添加为依赖关系:

Add it as a dependency:

angular.module('app').requires.push('app.controllers');

这篇关于angular.bootstrap后角添加模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆