[英]Angularfire show key and value
在我的angular項目中,我正在按以下方式使用angularfirebase保存用戶的顯示名稱:
this.afDB.object('/users/' + this.userId).set({displayName: user.displayname })
這給出了這樣的東西...
然后為了顯示它,我正在做以下事情:
this.profileData = this.db.list(`/users/${this.userId}/`);
然后,在HTML中:
<p> {{(profileData | async)?. displayName}} </p> <!-- Doesn't show any -->
但是,它不顯示任何數據。
如果我在下面嘗試,那么它會顯示用戶名:
<div class="text" *ngFor="let item of profileData| async">
{{item.$value}} <!-- Shows the display name -->
</div>
我究竟做錯了什么? 因為只有一把鑰匙,所以我不需要*ngFor
,我感到困惑。 任何幫助都感激不盡。
謝謝!
編輯:
我只是試圖使用this.userId
顯示登錄用戶的顯示名稱。 在此示例中,假設登錄用戶的ID為“ se5Zmy8n ...”(img中的最后一個)。 然后, displayName
將為“ asesdf4r”。
您正在訪問葉節點。 您需要升級才能訪問所有用戶
this.profileData = this.db.list('/users/');
列表將為您提供一個對象,其中包含作為用戶鍵的鍵。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.