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?

Rohit
  • 7,449
  • 9
  • 45
  • 55
  • Almost but not quite a duplicate: http://stackoverflow.com/questions/18875714/angular-js-re-open-and-add-dependencies-to-an-already-bootstrapped-application – Mark Amery Jan 27 '15 at 15:30

1 Answers1

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);
Tivie
  • 18,864
  • 5
  • 58
  • 77