【发布时间】:2018-09-10 19:04:48
【问题描述】:
我有这个效果,我正在尝试使用计时器每 x 秒轮询一次数据。但我无法弄清楚计时器应该如何与数据流交互。我尝试在顶部添加另一个 switchMap,但后来我无法将操作和有效负载传递给第二个 switchmap。有什么想法吗?
我查看了this post,但我的情况有点不同。我正在传递一个带有我需要访问的操作的有效负载,并且我正在使用 ngrx 6。
@Effect()
getData = this.actions$
.ofType(appActions.GET_PLOT_DATA)
.pipe(
switchMap((action$: appActions.GetPlotDataAction) => {
return this.http.post(
`http://${this.url}/data`,
action$.payload.getJson(),
{responseType: 'json', observe: 'body', headers: this.headers});
}),
map((plotData) => {
return {
type: appActions.LOAD_DATA_SUCCESS,
payload: plotData
}
}),
catchError((error) => throwError(error))
)
【问题讨论】:
-
谢谢,我看过那个,不过我使用的是 RXJS 6,我的操作有一个有效负载。所以我还没有完全能够得到它
标签: angular http rxjs ngrx ngrx-effects