ngrx - 没有减速器的 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!
解决方案
您需要StoreModule.forRoot()
在父模块中导入。如果它是你的根模块,那么在这里。StoreModule.forFeature('evaluation', {})
您可以在此处跳过的部分。
我就是这样做的:https ://take.ms/ZXxOx
推荐阅读
- python - Google Cloud VM 仍然使用 CPU 而不是 TPU 来执行 Python/Tensorflow 脚本
- laravel - 在 Laravel 中发送电子邮件后是否有任何事件
- python - 以矢量化方式查找不同元素的索引
- excel - 如果没有使用 VBA 的打开工作簿,如何使 Excel 实例可见
- javascript - 如何在 react.js 中从另一个类访问不同类的成员
- flutter - Flutter DropdownButton条件不起作用
- json - 当 Junit 测试失败时在文件中收集 JSON 对象
- c - 在二进制文件中使用 2 字节字符数组写入不寻常的额外 2 字节
- php - PHP / Wordpress -> 自动将用户密码更改从实时镜像到临时数据库
- c++ - static_cast 重定向到具有相同功能的多个类,即使它被强制转换为单个类?为什么这行得通?