有条件注入angularjs模块的初始化过程中依赖 [英] Conditionally inject dependencies during angularjs module initialization

查看:100
本文介绍了有条件注入angularjs模块的初始化过程中依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想有一个依赖注入其有条件地角模块。即。

I have an angular module which I want to have a dependency injected into it conditionally. i.e.

var myapp = angular.module('myapp', [
  'ngRoute',
  'myappcontroller',
  'ngGrid'              // I want to include ngGrid only if I am running a debug version of myapp
]);

有没有办法做到这一点?

Is there any way to do that?

推荐答案

可以,但有一点额外的工作。

You can, but with a bit of extra work.

第二个参数是这样一个数组所以没什么prevents你:

The second parameter is an array so nothing prevents you from doing this:

var dev = ['foo', 'bar'];
var prod = ['foo'];
var deps = dev; //or prod


angular.module('foo', []);
angular.module('bar', []);

angular.module('myApp', deps);

这篇关于有条件注入angularjs模块的初始化过程中依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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