使用这样的模型层次结构:
export class A {
constructor() {
// Here service X is needed for some own functions
}
}
export class B extends A {
constructor() {
// Here service Y is needed for some own functions
super( ... )
}
}
export class C extends B {
constructor(parent, data) {
super( ... )
}
}
我想实例化C对象。所以问题是:
如何注入X
和Y
服务?
C
构造函数上,并将它们传递给super
的基类吗? parent
和data
?Y
级别注入B
,在X
级别注入A
?所以我以某种方式避免在super
?答案 0 :(得分:1)
var els = document.getElementsByClassName('applications');
function addHandler(el) {
el.addEventListener("click", function() {
for(var x = 0; x < els.length; x++){
if(els[x] === el){
console.log("NOT ME!!!");
}else{
els[x].classList.remove("openDiv");
}
}
if(el.classList.contains("openDiv")){
el.classList.remove("openDiv");
}else{
el.classList.add("openDiv");
}
});
}
for (var i = 0; i < els.length; i++) {
addHandler(els[i]);
}
另见Angular2 access global service without including it in every constructor