このようなことは可能ですか?(私が試したが成功しなかったため):
@Injectable()
class A {
constructor(private http: Http){ // <-- Injection in root class
}
foo(){
this.http.get()...
};
}
@Injectable()
class B extends A{
bar() {
this.foo();
}
}
このようなことは可能ですか?(私が試したが成功しなかったため):
@Injectable()
class A {
constructor(private http: Http){ // <-- Injection in root class
}
foo(){
this.http.get()...
};
}
@Injectable()
class B extends A{
bar() {
this.foo();
}
}
種類 -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();
}
}
このディスカッションを参照してください。なぜそれを回避する方法がないのですか。
これで問題は確実に解決します。
@Injectable()
class A {
constructor(private http: Http){ // <-- Injection in root class
}
foo(http:Http){ //<------receive parameter as Http type
http.get()... //<------this will work for sure.
};
}
import {Http} from '@angular/http';
@Injectable()
class B extends A{
constructor(private http:Http){}
bar() {
this.foo(this.http); //<----- passing this.http as a parameter
}
}