DEV Community

Cover image for Consuming APIs in Angular: Displaying Data In Components

Consuming APIs in Angular: Displaying Data In Components

Florimond Manca on March 01, 2019

Welcome back! This article is a follow up to a previous article: Consuming APIs in Angular – The Model-Adap...
Collapse
 
gaurangdhorda profile image
GaurangDhorda

How to unsubscribe services in component after component destroy?

like this line of code " this.courseService.list().subscribe((courses: Course[]) "

how to unsubscribe ? Without unsubscribing Can we lead to memoryLeak of data overload?..

Collapse
 
florimondmanca profile image
Florimond Manca • Edited

Hi! This subscription won’t lead to memory leaks because it completes after the request finishes, i.e. the observable is bounded.

I’ve found this article useful to know when and how to unsubscribe from observables: netbasal.com/when-to-unsubscribe-i...

Collapse
 
gaurangdhorda profile image
GaurangDhorda

Thank you so much for this information!. helps to clear doubts on unsubscribing cases in one document shred by you. :)

Collapse
 
agarwalakash profile image
Akash Agarwal

Won't any Observable be returned from the service to the component? As there wasn't any request being made in the service.

Collapse
 
florimondmanca profile image
Florimond Manca

Hey! Thanks for chiming in. The code is available in the original article, so I cropped it for brevity, but I just added the part that defines the list() method. :-)

Collapse
 
agarwalakash profile image
Akash Agarwal

Yeah I was wondering the same! I liked the way you described everything in detail. :)