【发布时间】:2017-10-03 22:33:13
【问题描述】:
我已经在 Angular 应用程序中使用 IntervalObservable 和 startWith 实现了 http 池以立即启动。我想知道 IntervalObservable 是否等到初始/上一个调用完成流数据? 有没有更好的方法在 Angular 应用中实现数据池。
来自 service.ts
getRecordsList() {
return IntervalObservable
.create(15000)
.startWith(0)
.flatMap((r) => this.http
.post(`http://services.com/restful/recordService/getRecordsList`, body, {
headers: new HttpHeaders().set('Content-Type', 'application/json')
}))
.shareReplay()
.catch(this.handleError);
}
来自 component.ts 的示例
ngOnInit() {
this.service.getRecordsList()
.subscribe(
(recordList) => {
this.recordResponse = recordList;
},
error => { console.log },
() => console.log("HTTP Observable getRecordsList() completed...")
);
}
我使用过 Angular httClient,我希望无论如何这都无关紧要。
【问题讨论】:
标签: angular rxjs angular-httpclient