kar*_*ina 6 dependency-injection inject injectable typescript angular
可以这样做吗?(因为我试过,但没有成功):
@Injectable()
class A {
constructor(private http: Http){ // <-- Injection in root class
}
foo(){
this.http.get()...
};
}
@Injectable()
class B extends A{
bar() {
this.foo();
}
}
Run Code Online (Sandbox Code Playgroud)
有点 - 你必须super
调用你的基类的构造函数.只需传递所需的依赖项:
@Injectable()
class A {
constructor(private http: Http){ // <-- Injection in root class
}
foo(){
this.http.get()...
};
}
@Injectable()
class B extends A{
constructor(http: Http) {
super(http);
}
bar() {
this.foo();
}
}
Run Code Online (Sandbox Code Playgroud)
看到这个讨论,为什么没有办法解决它.
归档时间: |
|
查看次数: |
1763 次 |
最近记录: |