如何修改 angular 中当前注入的依赖项列表
how to modify the list of currently injected dependencies in angular
我正在尝试创建一个模块化 angular 应用程序,该应用程序能够在后端面板中插入新模块或删除当前添加的模块。
- 如何获取当前添加的依赖列表
angular 应用程序?
- 我该如何修改它们? (插入、删除)。
模块依赖项列表在模块的 requires
属性 中。
例如
var app = angular.module("app", ["dep1"]);
console.log(app.requires);
您可以尝试在 运行 时间内将依赖项添加到此列表。这个简单的例子对我有用。
(function() {
"use strict";
var app1 = angular.module("ag.test", []);
app1.factory("agTestFactory", [function() {
return {
hello: function() {
console.log("hello");
}
};
}]);
var app = angular.module("app", ["app.configurations", "app.routes"]);
app.requires[app.requires.length] = "ag.test";
app.run(["agTestFactory", function(tf) {
tf.hello();
}]);
})();
如果这还不能解决你的问题,什么时候可以看看这个话题。
https://groups.google.com/forum/#!topic/angular/w0ZEBz02l8s
我正在尝试创建一个模块化 angular 应用程序,该应用程序能够在后端面板中插入新模块或删除当前添加的模块。
- 如何获取当前添加的依赖列表 angular 应用程序?
- 我该如何修改它们? (插入、删除)。
模块依赖项列表在模块的 requires
属性 中。
例如
var app = angular.module("app", ["dep1"]);
console.log(app.requires);
您可以尝试在 运行 时间内将依赖项添加到此列表。这个简单的例子对我有用。
(function() {
"use strict";
var app1 = angular.module("ag.test", []);
app1.factory("agTestFactory", [function() {
return {
hello: function() {
console.log("hello");
}
};
}]);
var app = angular.module("app", ["app.configurations", "app.routes"]);
app.requires[app.requires.length] = "ag.test";
app.run(["agTestFactory", function(tf) {
tf.hello();
}]);
})();
如果这还不能解决你的问题,什么时候可以看看这个话题。 https://groups.google.com/forum/#!topic/angular/w0ZEBz02l8s