Angular · Middle · Question 52 of 75

How do you get a single value from an Observable with async/await?

const user = await firstValueFrom(this.http.get<User>('/api/me'));

Explanation

toPromise() is deprecated. firstValueFrom resolves on the first value and unsubscribes; it rejects if the stream completes without values.

Further reading

Problem with a question

Angular · Middle · question 52

Test yourself

Take the Angular · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz