首页 > 解决方案 > 没有减速器的 Ngrx 商店?仅调度一个动作以被效果捕获

问题描述

我希望我的页面在 上调度一个动作ngOnInit,该动作将被效果捕获,并且效果将this.router.navigate(['path'])指向新路径。

我这里不需要任何减速器。

但我无法让它工作,因为this.store.dispatch()只有当我将我的商店作为 DI 注入并将其输入为我的当前状态时才会工作,就像这样private store: State<fromReducers.State>

我的模块像这样导入了商店:

@NgModule({
  imports: [
    CommonModule,
    RouterModule.forChild([
      { path: '', pathMatch: 'full', component: EvaluationContainer }
    ]),
    StoreModule.forFeature('evaluation', {}),
    EffectsModule.forFeature(Effects)
  ],
  declarations: [EvaluationContainer]
})
export class FeatureEvaluationModule {}

How can I still dispatch the action in this situation?

Thanks!

标签: ngrx

解决方案


您需要StoreModule.forRoot()在父模块中导入。如果它是你的根模块,那么在这里。StoreModule.forFeature('evaluation', {})您可以在此处跳过的部分。

我就是这样做的:https ://take.ms/ZXxOx


推荐阅读