I tried injecting one service in another using DI of angular 2
import {HttpService} from 'scripts/httpService';
export class CurrentBlog{
constructor(public httpService:HttpService){}
}
When I do this, I get this error :
Cannot resolve all parameters for CurrentBlog(?). Make sure they all have valid type or annotations.
I have tested DI with normal components and it works fine. But when I inject it in service. It simply doesn't work.
In angular 2 you need to make the angular injector aware of your service. To do this you need to mark the service as Injectable.
HttpService
import {Injectable} from 'angular2/angular2';
@Injectable()
export class HttpService{
...
}
CurrentBlog
import {HttpService} from 'scripts/httpService';
import {Inject} from 'angular2/core';
export class CurrentBlog{
constructor(public httpService:HttpService){}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With