Issue
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!
Solution
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){
}
Answered By - Abdulrahman Alsoghayer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.