我想从指定用户的firebase获取用户个人资料数据。 通过实例我想要返回显示名称和UID HBJKD12345
的用户的电子邮件地址我使用这个功能:
this.userProfile = this.af.database.object('/users/'+this.authInfo.uid)
但是console.log(this.userProfile.email)
我得到了一个“未定义”
在我看来,我必须使用:{{(userProfile | async )?.email}}
通过这一行,我可以显示用户的电子邮件地址,但是当我尝试使用console.log时,为什么会出现“Undefined”?
答案 0 :(得分:1)
您的观点因async
而有效。它揭开了实际价值。对于console.log()
,您需要做类似的事情。试试this.userProfile.$value()
。
查看https://github.com/angular/angularfire2/blob/master/docs/2-retrieving-data-as-objects.md#meta-fields-on-the-object或https://github.com/angular/angularfire2/blob/master/docs/2-retrieving-data-as-objects.md#meta-fields-on-the-object