小编Xua*_*yen的帖子

使用 ofType 访问 @ngrx 效果中的动作道具,用于多个动作

我使用ofType运算符有 2 个动作和这 2 个动作的效果,如下所示:

export const myActions = {
  actionA: createAction(`actionA`, props<{ a: string }>()),
  actionB: createAction(`actionB`, props<{ b: number }>())
}

myEffect$ = createEffect(() =>
  this.actions$.pipe(
    ofType(myActions.actionA, myActions.actionB),
    mergeMap(action => {
      // How to convert action object to correct type and access action.a or action.b props?
      if (action.type == myActions.actionA) {
        console.log(action.a); // compile error
      } else if (action.type == myActions.actionB) {
        console.log(action.b); // compile error
      }
    })
  ), {dispatch: false}
);
Run Code Online (Sandbox Code Playgroud)

如何检查和访问动作的道具(action.a 和 action.b)并从 IDE …

javascript typescript redux ngrx angular

4
推荐指数
1
解决办法
2104
查看次数

标签 统计

angular ×1

javascript ×1

ngrx ×1

redux ×1

typescript ×1