Javascript 在angularjs中获取模块名及其所有依赖项列表

Javascript 在angularjs中获取模块名及其所有依赖项列表,javascript,angularjs,Javascript,Angularjs,我想获得模块名和所有依赖项列表,即在应用程序模块中注入的 比如: var app = angular.module( 'wp', ['ngRoute', 'abc', 'xyz'] ); 因此,我想从中获得所有组件列表,如wp、ngRoute、abc、xyz 使用角度JS。 感谢angular js中的,您可以使用requires数组获取主模块的所有依赖模块 模块声明的语法: angular.module(名称,[requires],[configFn]) 第二个参数是名为requires的数

我想获得
模块名
所有依赖项列表
,即
应用程序模块
中注入的

比如:

var app = angular.module( 'wp', ['ngRoute', 'abc', 'xyz'] );
因此,我想从中获得所有组件列表,如
wp、ngRoute、abc、xyz

使用角度JS。


感谢angular js中的,您可以使用
requires
数组获取主模块的所有依赖模块

模块声明的语法:

angular.module(名称,[requires],[configFn])

第二个参数是名为requires的数组中的依赖项

因此,app.requires会为您提供所需的结果。

以下是一个例子:

var app = angular.module('App', [
    'ngRoute',
    'appServices',
    'toaster',
    'ngValidate',
    'uiGmapgoogle-maps',
    'ngFileUpload',
    'offClick'
]);
控制台日志(应用程序需要)

给你

Array[8] 

[
"ngRoute",
"appServices",
"toaster",
"ngValidate",
"uiGmapgoogle-maps",
"ngSanitize",
"ngFileUpload",
"offClick"
]
更新:

1)如果模块没有变量,可以使用

angular.module('App')。需要

2)如果您根本不知道模块名称,则可以使用

angular.module($rootElement.attr('ng-app'))需要

为此,您应该添加
$rootElement
作为依赖项

例如:

3)即使您没有代码,也可以尝试,
$(“[ng-app]”)。attr('ng-app')
如果您有jquery来获取模块名称


angular.module($(“[ng-app]”)attr('ng-app'))需要

假设我没有这个变量名
app
,那么你可以使用,
console.log(angular.module('app')。requires)@Sravan…有用的信息,但我想知道一件事,如问题中所述…..如果我也不知道模块名称,那么我们如何实现这一点?你的意思是你甚至不知道所声明模块的名称?是吗?为此,您可以使用,
(angular.module($rootElement.attr('ng-app'))requires)
,需要添加
$rootElement
作为依赖项。
.run(["$rootScope","$rootElement",function($rootScope,$rootElement){

   console.log(angular.module('App').requires);

   console.log(angular.module($rootElement.attr('ng-app')).requires);

}]);