我很难理解Angular中的依赖注入.所以我的问题是,任何人都可以解释哪些"类型",如控制器,工厂,提供商等,我们可以注入其他类型,包括相同"类型"的其他实例?
我实际上正在寻找的是这个表充满了y/n.对于具有相同行/列的单元格,这意味着将一个"类型"的值注入另一个具有相同"类型"的另一个"类型"
+----------------+----------+------------+-----------+---------+--------+----------+---------+-------+
| Can we inject? | Constant | Controller | Directive | Factory | Filter | Provider | Service | Value |
+----------------+----------+------------+-----------+---------+--------+----------+---------+-------+
| Constant | | | | | | | | |
| Controller | | | | | | | | |
| Directive | | | | | | | | |
| Factory | | | | | | | | |
| Filter | | | | | | | | | …Run Code Online (Sandbox Code Playgroud) 我得到了角度服务,我需要配置,这样我就可以从我的应用程序中删除耦合并分享我的一些代码.
我的问题是你是如何实现这一目标的?
使用module.value()和依赖注入?那么你如何获得默认值?如何在init处计算值而不是硬编码?
有另一项服务?你怎么做那个通用的?
你有代码例子吗,因为我有点迷失了.
我想知道在angular2中设置可配置模块的最佳方法是什么.在angular1中,这通常是通过提供商完成的.随着它们的改变,你会如何将配置参数传递给可重用的ng2模块/指令/组件?
一个ng1的例子:
// configuring a (third party) module
.config(function (angularPromiseButtonsProvider) {
angularPromiseButtonsProvider.extendConfig({
spinnerTpl: '<div class="other-class"></span>',
disableBtn: false
});
});
// setting up the provider
.provider('angularPromiseButtons', function angularPromiseButtonsProvider() {
var config = {
spinnerTpl: '<span class="btn-spinner"></span>',
priority: 0,
disableBtn: true,
};
return {
extendConfig: function(newConfig) {
config = angular.extend(config, newConfig);
},
$get: function() {
return {
config: config
};
}
};
})
// using the result in the directive, etc.
.directive('promiseBtn', function(angularPromiseButtons){
var config = angularPromiseButtons.config;
})
Run Code Online (Sandbox Code Playgroud)
这基本上与这个 …