Angular 2: Inject Service to another service. (No provider error)

后端 未结 3 557
傲寒
傲寒 2020-12-14 01:33

I want to inject a service to another service:

@Injectable()

export class Dispatcher {
}


@Injectable()

export class TodoStore {

    constructor(@Inject(         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-14 01:47

    A providers array is available in @NgModule. You can provide your service by declaring your service in that array.

    @NgModule({
        declarations:[...],
        imports:[...],
        providers: [MyCustomService],
        bootstrap:[AppComponent]
    })
    

提交回复
热议问题