21

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 1

30

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 !

Sign up to request clarification or add additional context in comments.

3 Comments

Of course you can implement a custom service ans each controller will say to this service : i'm ... Then you can call this service
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 :D
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]) })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.