问题描述
因此,由于V10升级到NGRX,您无法再将一种Action传递给效果,因为Actions现在被声明为类中的函数。在V10中还有解决此问题的方法吗?
export const myAction = createAction(
'[myAction]',props<{person: User}> ()
);
@Effect({ dispatch: false })
x = this.actions$.pipe(
ofType**<myAction>**('[myAction]'),
我无法使用人道具。您在第10版之前的位置是因为它是一类...
解决方法
请参见https://ngrx.io/guide/effects#incorporating-state
- 将
myAction
直接传递到ofType
- 该动作是根据其道具键入的,因此您只需使用
action.person
@Effect({ dispatch: false })
x = this.actions$.pipe(
ofType(myAction),map(action => of(action.person))
);
另外,最好使用新的createEffect
语法。
Stackblitz:https://stackblitz.com/edit/so-ngrx-oftype?file=index.ts