2016-09-12 35 views

Odpowiedz

4

Rodzaju - trzeba dokonać super wywołanie konstruktora klasy bazowej. Wystarczy przejść w dół potrzebnych zależności:

@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(); 
    } 
} 

Zobacz this discussion, dlaczego nie ma sposobu, wokół niego.

0

To na pewno rozwiąże Twój problem.

@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 
    } 
}