I am writing a web app with many custom directives. Is there a way to view all the directives that have been registered for each module?
Modules have an _invokeQueue, which contains the contents of the module. A function like this:
function Directives(module) {
var directives = [];
var invokes = angular.module(module)._invokeQueue;
for (var i in invokes) {
if (invokes[i][1] === "directive") directives.push(invokes[i][2]);
}
return directives;
}
will run through the module and grab each element in the invoke queue that are tagged as directives.
Here is a fiddle where you can play with it.
EDIT: I made this slightly more generic, since I'm not sure which case you wanted.
Since modules can include other modules, this will allow you to recursively gather the directives that are in sub modules. http://jsfiddle.net/V7BUw/2/.
the main difference is you need to repeat for every module in the requires array as well:
for (var j in module.requires) {
Directives(module.requires[j], directives);
}
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With