DEV Community

loading...

Discussion on: How to Avoid Observables in Angular

Collapse
rubenheymans profile image
Ruben

How about just do it like this :
async foo() {
this.user = await observable.pipe(take(1)).toPromise();
// this.user.id works here
}

Collapse
lewislbr profile image
Lewis Llobera

It seems that won't be an option in the future: indepth.dev/rxjs-heads-up-topromis...

Collapse
baluditor profile image
Baluditor

I only registered to this site, to say Thank You for this comment of yours. I've had trying to figure out how to to this and your comment ended a 7 hours long search. Thanks!

Collapse
rubenheymans profile image
Ruben

I really don't get why this isn't mentioned more. This way you can easily escape the observable horror when you don't need it. Also async await makes you code so much cleaner, most examples use .then() for some reason.

Thread Thread
xtealer profile image
XTEALER

It's just true!