I am using Angular 2 rc3.
I have a service that returns an rxjs Observable, inside which there are some asynchronous tasks, and then a recursive HTTP request. This is a fragmented load, so there are several consecutive requests, each of which is launched in the success handler of the previous fragment.
I would like to know how to cancel an internal HTTP request when I have a containing Observable.
This is basically what I am doing (not real code):
upload (file) {
return Observable.create((observer) => {
let reader = new FileReader();
let chunkedFile = this.chunkFile(file);
reader.onloadend = (event) => {
this.http.put('url/to/upload/to', chunkedFile.currentChunk)
.subscribe((res) => {
observer.next(res);
this.uploadFileInChunks(reader, chunkedFile, observer);
});
};
this.uploadFileInChunks(reader, chunkedFile, observer);
});
}
And then I use it in my component as follows:
upload () {
this.uploader = this.uploadService.upload(file)
.subscribe((res) => {
})
}
ngOnDestroy () {
this.uploader.dispose();
}
I see on the network panel that after the destruction of the component, the download process continues.
How can i cancel it?
, https://github.com/kinstephen/angular-azure-blob-upload Angular 2