jay*_*ani 1 javascript angularjs
我想要得到module name,all dependencies list那是injected在application module.
喜欢 :
var app = angular.module( 'wp', ['ngRoute', 'abc', 'xyz'] );
Run Code Online (Sandbox Code Playgroud)
所以从这里我想得到所有这些组件列表,例如wp,ngRoute,abc,xyz
使用Angular JS.
谢谢
在Angular js中,可以使用requires数组来获取主模块的所有依赖模块。
模块声明的语法:
angular.module(name, [requires], [configFn]);
第二个参数是名为 require 的数组中的依赖项。
因此,app.requires 为您提供了所需的结果。
这是一个例子:
var app = angular.module('App', [
'ngRoute',
'appServices',
'toaster',
'ngValidate',
'uiGmapgoogle-maps',
'ngFileUpload',
'offClick'
]);
Run Code Online (Sandbox Code Playgroud)
console.log(app.requires);
给你,
Array[8]
[
"ngRoute",
"appServices",
"toaster",
"ngValidate",
"uiGmapgoogle-maps",
"ngSanitize",
"ngFileUpload",
"offClick"
]
Run Code Online (Sandbox Code Playgroud)
更新:
1)如果你的模块没有变量,你可以使用,
angular.module('App').requires
2)如果你根本不知道模块名称,那么你可以使用,
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);
}]);
Run Code Online (Sandbox Code Playgroud)
3)即使你没有代码,
$("[ng-app]").attr('ng-app')如果你有 jquery 来获取模块名称,你也可以简单地尝试一下。
angular.module($("[ng-app]").attr('ng-app')).requires;
| 归档时间: |
|
| 查看次数: |
2554 次 |
| 最近记录: |