Is it possible to do something like this? (because I tried and failed):
@Injectable() class A { constructor(private http: Http){ // <-- Injection in root class } foo(){ this.http.get()... }; } @Injectable() class B extends A{ bar() { this.foo(); } }
View - you must make a call to super constructor of the base class. Just do the necessary dependencies:
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(); } }
See this discussion on why there is no way around this.
This will solve your problem for sure.
@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 } }