10

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?

1

1 Answer 1

13

You can, but with a bit of extra work.

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);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.