0
votes

In my angular project, I am using angularfirebase as below to save user displayname:

this.afDB.object('/users/' + this.userId).set({displayName: user.displayname })

Which gives something like this...

enter image description here

Then in order to display it, I am doing the following:

this.profileData = this.db.list(`/users/${this.userId}/`);   

Then, in HTML:

<p> {{(profileData | async)?. displayName}} </p> <!-- Doesn't show any -->

However, it doesn't show any data.

If I try below, then it does show the user name:

<div class="text" *ngFor="let item of profileData| async">
     {{item.$value}} <!-- Shows the display name -->
</div> 

What am I doing wrong? Since there is only one key, I don't need *ngFor and I am baffled. Any help will be much appreciated.

Thanks!

EDIT:

I am simply trying to show the logged-in user display name by using this.userId. In this example, let say the logged-in user has id of "se5Zmy8n..." (the last one in the img). Then the displayName would be "asesdf4r".

1
With <div class="text" *ngFor="let item of profileData| async">{{item.$value}}</div>, I get asesdf4r as the result. With <p> {{(profileData | async)?. displayName}} </p>, just a blank. And no i am not using jquery. I have been on this issue for two days and it is driving me crazy lol. - Steve Kim
Yeah,, nothing.. Just a blank. - Steve Kim
Just shows as [object Object]. I looked at the console.log and just shows "FirebaseListObservable" (imgur.com/a/Cr2VW). - Steve Kim
I know I am getting something since {{item.$value}} shows the right info. It's just pain in the arse to avoid using *ngFor. - Steve Kim
Yes and no, for me it means that profileData doesn't have displayName attribute - Vega

1 Answers

0
votes

You're access a leaf node. You need to go one level up to access all users

this.profileData = this.db.list('/users/');  

List will give you an object with keys that are your user keys.