DEV Community

Analyze ways to retrieve data with signals and HttpClient in Angular

Connie Leung on February 15, 2024

Introduction In this blog post, I would like to discuss how signal and HttpClient can retrieve data in Angular. In my observation, I fo...
Collapse
 
siva678 profile image
Sivasankaran

Very simple and clear explanation. Thanks @railsstudent 🙏

Collapse
 
railsstudent profile image
Connie Leung

Thank you so much for your support

Collapse
 
jangelodev profile image
João Angelo

Hi Connie Leung,
Your tips are very useful
Thanks for sharing

Collapse
 
railsstudent profile image
Connie Leung

Thank you so much

Collapse
 
rainerhahnekamp profile image
Rainer Hahnekamp

Good overview, well done!

Connie, what do you say about not using HttpClient at all but a fetch with async/await and adding some features around that?

Collapse
 
railsstudent profile image
Connie Leung

I will continue to use HttpClient.get because there are some use cases that RxJS is good at.

  1. I can pipe the Observable to switchMap to cancel the previous unfinished request and begin a new one.
  2. I can pipe the Observable to retry operator to retry the requests a specific number of times before emitting an error.
  3. When I want to receive the results of multiple HTTP requests before proceeding to the next step, I prefer forkJoin operator over Promise.all that is the Promise equivalence.

RxJS also has lastValueFrom to convert Observable to Promise. For Angular developers who want to deal with Promises, they can check out firstValueFrom and lastValueFrom in the RxJS Doc.

By the way, I love your ng news updates and youtube. It helps me keep up-to-date to the latest Angular news and Ngrx Signal Store