DEV Community

Discussion on: + async/await

melaniecarr23 profile image

I tried this using HttpClient and a data service for my angular project, and it returns the mapped object, but the value of that http function is an observable object. I've no clue what I'm doing wrong to not get the right value.

nyagarcia profile image
Nya Author

The Angular HttpClient is designed to work with Observables (data streams), and this approach is Promise-based. You have two options:

  1. Work with Observables, where you have to subscribe to the Observable object in order to access its data. You can find more information here

  2. You can you use the toPromise() utility, which will transform the Observable you are receiving to a Promise, which you can then handle in the traditional way. More info about toPromise here

I hope this helps you out. Let me know :)