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'));- ✓Correct answer: With
firstValueFrom(orlastValueFrom) from RxJS - 2With
await observable - 3With
observable.toPromise()- the recommended modern API
Explanation
toPromise() is deprecated. firstValueFrom resolves on the first value and unsubscribes; it rejects if the stream completes without values.