简体   繁体   English

Angularfire展示关键和价值

[英]Angularfire show key and value

In my angular project, I am using angularfirebase as below to save user displayname: 在我的angular项目中,我正在按以下方式使用angularfirebase保存用户的显示名称:

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

Which gives something like this... 这给出了这样的东西...

在此处输入图片说明

Then in order to display it, I am doing the following: 然后为了显示它,我正在做以下事情:

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

Then, in HTML: 然后,在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. 因为只有一把钥匙,所以我不需要*ngFor ,我感到困惑。 Any help will be much appreciated. 任何帮助都感激不尽。

Thanks! 谢谢!

EDIT: 编辑:

I am simply trying to show the logged-in user display name by using this.userId . 我只是试图使用this.userId显示登录用户的显示名称。 In this example, let say the logged-in user has id of "se5Zmy8n..." (the last one in the img). 在此示例中,假设登录用户的ID为“ se5Zmy8n ...”(img中的最后一个)。 Then the displayName would be "asesdf4r". 然后, displayName将为“ asesdf4r”。

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. 列表将为您提供一个对象,其中包含作为用户键的键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM