Say I have an angular app, that has some modules and some directives.
I want to get a list of all the defined directives in this app.
For example:
var myModule = angular.module('myModule', [function(){...}]);
myModule.directive('myDirective', [function () {...}]);
myModule.directive('myOtherDirective', [function () {...}]);
var myOtherModule = angular.module('myOtherModule', [function(){...}]);
myOtherModule.directive('thirdDirective', [function () {...}]);
I want to write a function getAllDirectives()
that will return ['myDirective','myOtherDirective','thirdDirective']
.
Also if possible I would also like to know which module each directive belongs to:
{
'myModule': ['myDirective','myOtherDirective'],
'myOtherModule':['thirdDirective']
}
How can this be done?
Please note that I need to do this from outside the app itself and after it has already loaded. I do have access to anything publicly available on the page, such as the angular
object and the DOM
.