Is there a way to list all of the directives and controllers that have been defined for a given angular module? For example, imagine I define three controllers in the 'main' module (i.e. angular.module('main').controller('MainCtrl',function() {...}). Is there are way to get the list of those three controllers?
1 Answer
Hmm really hard and not a good thing i think but :
var app = angular.module('MyApp', []);
console.log(app._invokeQueue[0][2][1]);
_invokeQueue is an array if you do that for each entry getting the [0][2][1] you'll see the name of each provider in your module.
If you lok the _invokeQueue alone you'll see a lot of things that you'll like the name of the provider like below but his type too (directive, controller, ...);
But you feel that this is a tricky thing not a good thing a really bad practice but anyway really fun.
Don't use it in production !
3 Comments
Thomas Pons
Of course you can implement a custom service ans each controller will say to this service : i'm ... Then you can call this service
Dane Macaulay
This was very useful in identifying issues with dependency injection after variable mangling my project with uglifyJS. Thanks!
angular.module('myApp')['_invokeQueue'].forEach(function(value){ console.log(value[2][1]) }) You can see the usage of DI Annotation, or lack thereof :DJosh Russo
if you use
values[2][0] you actually get a list of injectable names angular.module('qirt')['_invokeQueue'].forEach(function(value){ console.log(value[2][0]) })