I need to do API calls to display the progress of something.
I have created a service which does this every 1.5 seconds
Main Component
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));
}
The call works, but it keeps going. I want to stop doing the API call when the progress is finished (if (!data.InProgress
) but I'm stuck on this.
How can I correctly unsubscribe from this observable when if (!data.InProgress)
?
Thanks