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)
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.
So you can't unsubscribe to it(promise).
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() .
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With