【发布时间】:2018-12-05 21:50:37
【问题描述】:
在我的组件 html 中,我使用 asyncPipe 订阅此 http 服务。该服务将 json 响应对象映射到类实例数组。这一切都很好,但我希望 http 服务每隔几秒钟轮询一次。我已经尝试了很多东西(比如间隔),但目前看来 RXJS 有点雷区。有没有人使用 Angular 6 实现过这种东西?
fetch(command, params?) {
return this.http.post(`http://localhost:4000/${command}`, params)
.pipe(
map((data: Data) => {
const statuses: Status[] = [];
for (const statusKey of Object.keys(data.statuses)) {
const newStatus = new Status(
// do some object translation...
);
statuses.push(newStatus);
}
return statuses;
})
)
.pipe(
catchError(EpisodeApiService.handleError)
);
}
【问题讨论】:
标签: angular typescript rxjs angular-httpclient