List of registered user directives in AngularJS

I am writing a web application with many custom directives. Is there a way to view all the directives that have been registered for each module?

+4
source share
1 answer

Modules have _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 go through the module and capture every element in the call queue, which are marked as directives.

Here is a fiddle where you can play with it.

EDIT: I made this a little more general, as I am not sure which case you wanted.

, , . http://jsfiddle.net/V7BUw/2/.

, require:

for (var j in module.requires) {
    Directives(module.requires[j], directives);
}

, !

+8

All Articles