我需要做API調用來顯示某些事情的進度。長角度投票4
我創建了這個做每1.5秒
主要成分
private getProgress() {
this.progressService.getExportProgress(this.type, this.details.RequestID);
}
Services.ts
public getExportProgress(type: string, requestId: string) {
Observable.interval(1500)
.switchMap(() => this.http.get(this.apiEndpoint + "Definition/" + type + "/Progress/" + requestId))
.map((data) => data.json().Data)
.subscribe(
(data) => {
if (!data.InProgress)
//Stop doing this api call
},
error => this.handleError(error));
}
呼叫作品的服務,但它一直會。當進程完成時,我想停止執行API調用(if (!data.InProgress
),但我堅持這一點。
如何在if (!data.InProgress)
時正確取消訂閱此可觀察項?
感謝