Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular HttpClient unsubscribe [duplicate]

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.

like image 801
Antediluvian Avatar asked Oct 18 '19 03:10

Antediluvian


1 Answers

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

like image 83
sibabrat swain Avatar answered Oct 24 '22 02:10

sibabrat swain