Is there a need to unsubscribe from the Observable
the Angular HttpClient
's methods return?
For example:
this.http.get(url).subscribe(x => this.doSomething());
Do I need to unsubscribe from this subscription? I am asking this is because I don't know if Angular handles it itself. Plus the request is one-off not continuously. I tend to think I don't need to. What are your thoughts?
As per the below post: Angular/RxJs When should I unsubscribe from `Subscription`
RxJS handles the one-off subscription but I didn't find anything in their doc.
No, You don't need to unsubscribe it. It observes until getting a response from api. And once the Http request completes it unsubscribes automatically.
Refer to this
Why not to unsubscribe Http Observables
Angular guide http
AsyncPipe
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