Angular how to get the attribute of a Promise<Object>?

Viewed 28

I have an Angular 13 application with Oauth authentication, and I can't retrieve my session information with the loadUserProfile() function which returns a Pomise

I have to have the username information in my menu I have not arrived if I convert to json I have an out of memory because it changes my profile to infinity.

{{name | async}}
get name() {
 
    return this.oauthService.loadUserProfile();
}
1 Answers

Why not simply use a local variable for the userProfile after it loaded?

this.oauthService.loadUserProfile().then((value) => {
  this.name = value
  // Trigger cdr.markForCheck() if needed
})

Then use name on your template

But i wonder why this.oauthService.loadUserProfile() return a promise instead of an observable?, if it return an observable as default in http request, you can use {{ name | async }} easily in your template

Related