【发布时间】:2021-01-01 04:23:50
【问题描述】:
我正在尝试制作一个可以做很多事情并返回成功/失败操作的效果。
这是我正在做的简化版本:
UploadSolidModel$ = this.actions$.pipe(
ofType<featureActions.UploadSolidRequest>(featureActions.ActionTypes.UploadSolidRequest),
switchMap((action) =>
// 1) return an observable with elevation
this.altimeterService.getElevation()
// 2) use the above result to make some change and dispatch an API call that return an observable
.pipe(
switchMap((elevation) =>
this.dataService.uploadSolid()
)
)
// 3.a) use the response from the previous api call to dispatch a success/fail effect
.pipe(
map((response) => {
return new ActionSuccess;
}),
// 3) 3.b) use the failure of the api call to dispatch failure effect
catchError((error: HttpErrorResponse) => {
return of(new featureActions.UploadSolidFailed({ error: error.message }));
})
)
)
我遇到的问题是 NgRx 告诉我我的效果是调度一个无效的动作。 我的链条一定是错的,但我试图修复它,但找不到解决方法。
【问题讨论】:
-
如果 3a 中的响应来自
dataService.uploadSolid,那么您的pipe级别错误,它应该从uploadSolid链接起来
标签: javascript rxjs ngrx