Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unsubscribe observable's promise

How do I unsubscribe an observable if it's converted to promise? I'm using RxJS in Angular 2

import 'rxjs/add/operator/toPromise';

return this.http.get(this.heroesUrl)
                  .toPromise()
                  .then(this.extractData)
like image 993
Ankush Avatar asked Sep 25 '16 04:09

Ankush


People also ask

Do you need to unsubscribe from observable?

In Angular applications, it's always recommended to unsubscribe the observables to gain benefits like: Avoids Memory Leaks. Aborting HTTP requests to avoid unwanted calls.

Can we unsubscribe promise in Angular?

So you can't unsubscribe to it(promise).

How do I unsubscribe from observable RxJS?

Unsubscribing Manually One method we can use, is to unsubscribe manually from active subscriptions when we no longer require them. RxJS provides us with a convenient method to do this. It lives on the Subscription object and is simply called . unsubscribe() .


Video Answer


1 Answers

If you subscribe to an Observable then it is possible to unsubscribe to it.

When you return promise(here it seems you return promise -not observable), you usually don't subscribe to it. right??
So you can't unsubscribe to it(promise).

like image 184
Nikhil Shah Avatar answered Sep 27 '22 22:09

Nikhil Shah