Hon*_*iao 1 typescript rxjs5 ngrx angular
我正在使用ngrx.我收到了错误
无法读取未定义的属性"类型"
这是我的代码的一部分:
@Effect() foo$ = this.actions$
.ofType(Actions.FOO)
.withLatestFrom(this.store, (action, state) => ({ action, state }))
.map(({ action, state }) => {
if (state.foo.isCool) {
return { type: Actions.BAR };
}
});
Run Code Online (Sandbox Code Playgroud)
这个问题有点棘手,因为根据错误找到问题并不容易.
在这种情况下,如果state.foo.isCool是false,则返回执行任何操作.
因此,改变这样的事情将解决问题:
@Effect() foo$ = this.actions$
.ofType(Actions.FOO)
.withLatestFrom(this.store, (action, state) => ({ action, state }))
.map(({ action, state }) => {
if (state.foo.isCool) {
return { type: Actions.BAR };
}
return { type: Actions.SOMETHING_ELSE };
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1866 次 |
| 最近记录: |