javascript - How to get all directive names in a given angular app? -
say have angular app, has modules , directives.
want list of defined directives in 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 write function getalldirectives()
return ['mydirective','myotherdirective','thirddirective']
.
also if possible know module each directive belongs to:
{ 'mymodule': ['mydirective','myotherdirective'], 'myothermodule':['thirddirective'] }
how can done?
please note need outside app , after has loaded. have access publicly available on page, such angular
object , dom
.
you can directives defined in each module using custom function one:
function get_directives(name) { var result = [], invokes = angular.module(name)._invokequeue; for(var i=0; i<invokes.length; ++i) { if(invokes[i][1] == "directive") { result.push(invokes[i][2][0]); } } return result; } var result = { 'mymodule': get_directives('mymodule'), 'myothermodule': get_directives('myothermodule'), };
you inspect angular.module('module_name')._invokequeue
list future knowledge.
Comments
Post a Comment