不能完全肯定我明白你正在嘗試做的(沒有看到更多的代碼),但我想你正在嘗試做可以做到用工廠的提供者配置
providers: [
{
provide: WhateverService,
useFactory: (things: Things, to: To, inject: Inject) => {
// Not 100% sure, but I believe the return should be
// synchronous. If you have some asynchronous actions
// to be resolved first, you may just want to pass the
// Promise or Observable to the constructor
return new WhateverService(...);
},
deps: [Things, To, Inject]
}
]
在您StoreModule
,它可以像
@NgModule({})
export class StoreModule {
static provideStore(variable) {
return {
ngModule: StoreModule,
providers: [
{
provide: WhateverService,
useFactory: (things: Things, to: To, inject: Inject) => {
// use variable here
return new WhateverService(...);
},
deps: [Things, To, Inject]
}
]
}
}
}
另一種選擇,如果你想引導之前解決一些偏遠的數據,是做這樣的事情this。除此之外,我可能會完全關閉,因爲我對ngrx不熟悉。
我使用了來自鏈接回覆http://stackoverflow.com/a/39454713/536299的示例。非常感謝。 – balteo