I want to inject a service to another service:
@Injectable() export class Dispatcher { } @Injectable() export class TodoStore { constructor(@Inject(Dispatcher) dispatcher:Dispatcher){ } } But I always get Error: No provider for Dispatcher!
Thanks.
You need to provide your service somewhere. Please refer to angular2 docs
You could provide it in the bootstrap method:
bootstrap(AppComponent,[TodoStore,Dispatcher]); or the app component:
@Component({ ... providers:[TodoStore,Dispatcher] } ... Or in any other component, depending on your needs.
Also, you don't need to @Inject(Dispatcher) in the constructor. It's basically the same as
constructor(dispacher:Dispatcher){ } Oh yeah, welcome to SO :)
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