我用httpRequest编写了ngrx效果,该效果使用action.payload的动作。
从请求中我获取了在地图运算符中使用的数据(如果发生错误,我将在catchError中对其进行处理)
从后端我仅获得布尔值,如何将Action.payload从Action传播到map或catchError运算符?
示例:
effect= this.actions$
.ofType(Actions.IS_OK)
.pipe(
mergeMap(action => this.service.isOk(action.payload),
map((isOk: boolean) => new SuccessAction(isOk, action.payload), //here I need somehow get to action.payload value
catchError(error => of(new ErrorAction(error, action.payload))) //here I need somehow get to action.payload value
);
我无法存储要存储的有效负载,因为我触发了更多操作:Actions.IS_OK
感谢帮助
答案 0 :(得分:1)
您可以尝试:
effect = this.actions$
.ofType(Actions.IS_OK)
.pipe(
mergeMap(action => this.service.isOk(action.payload).pipe(
map((isOk: boolean) => { payload: action.payload, isOk: isOk} )
),
// need to create proper interface forPayload + isOk
map((payloadPlusIsOk: any) => new SuccessAction(payloadPlusIsOk.isOk, payloadPlusIsOk.payload),
catchError(error => of(new ErrorAction(error, action.payload))) //here I need somehow get to action.payload value
);