Dániel Kis Dániel Kis - 1 month ago 20
TypeScript Question

Cancel http request

In jQuery ajax there's a way to abort ajax queries:

var xhr = $.ajax({ ... });


when user wants to abort the operation or navigates to other page in a single page app I can call

xhr.abort();


In angular2-http api I cannot find any possibility to abort the query as it uses rxjs.

Is there a way to abort the ajax query in angular2?

Answer

When you subscribe, you get a subscription you can use to unsubscribe

this.httpSubscription = this.http.get(...).subscribe(...);
...
this.httpSubscription.unsubscribe();
Comments