List Dependencies

Is there any way to find out which dependencies were introduced into my Angular module?

angular.module('myModule', [ 'ui.bootstrap' ]) .controller('myController', [function () { // var dependencies = Magic.dependencies; // console.log(dependencies); }]); 
+7
javascript angularjs angularjs-controller angularjs-module
source share
2 answers

In your controller, if you enter $window , you can search for dependencies, in particular .requires exists on your module. To do this, you can declare module as a global var so that we can find it on our $window , in this case, call it app - or - you can bypass the global variables and $window and call angular.module('myModule').requires directly.

  • I added ngRoute to prove an array of dependencies that will be discoverable.


 var app = angular.module('myModule', [ 'ui.bootstrap', 'ngRoute' ]).controller('ctrl', ['$scope', '$window', function($scope, $window) { console.log($window.app.requires) // ["ui.bootstrap", "ngRoute"] console.log(angular.module('myModule').requires) // without global - $window not needed }]); 

JSFiddle Link - working example


Note. If you use global variables, you can simply call window as such: window.app.requires - without entering $window . However, see AngularJS $ window docs to see why $window is preferred.

+2
source share

Based on the @salniro answer , you don't need global variables or $window .

Dependencies are specified in the .requires angular.Module :

 angular.module('myModule', [ 'ui.bootstrap', 'ngRoute' ]) .controller('ctrl', function() { var app = angular.module('myModule'); console.log(app.requires); // ["ui.bootstrap", "ngRoute"] }); 

http://jsfiddle.net/8vtf6gar/1/

+1
source share