【发布时间】:2015-04-01 12:39:55
【问题描述】:
假设我有一个 Angular 应用程序,它有一些模块和一些指令。
我想获取此应用中所有已定义指令的列表。
例如:
var myModule = angular.module('myModule', [function(){...}]);
myModule.directive('myDirective', [function () {...}]);
myModule.directive('myOtherDirective', [function () {...}]);
var myOtherModule = angular.module('myOtherModule', [function(){...}]);
myOtherModule.directive('thirdDirective', [function () {...}]);
我想编写一个函数getAllDirectives(),它将返回['myDirective','myOtherDirective','thirdDirective']。
如果可能的话,我还想知道每个指令属于哪个模块:
{
'myModule': ['myDirective','myOtherDirective'],
'myOtherModule':['thirdDirective']
}
如何做到这一点?
请注意,我需要在应用程序本身之外并在它已经加载之后执行此操作。我确实可以访问页面上公开的任何内容,例如 angular 对象和 DOM。
【问题讨论】:
标签: javascript angularjs angularjs-directive