firebase函数af.database.object无法返回变量中的每个对象

时间:2016-06-26 20:40:22

标签: firebase ionic2 angularfire2

我想从指定用户的firebase获取用户个人资料数据。 通过实例我想要返回显示名称和UID HBJKD12345

的用户的电子邮件地址

我使用这个功能:

this.userProfile = this.af.database.object('/users/'+this.authInfo.uid)

但是console.log(this.userProfile.email)我得到了一个“未定义”

在我看来,我必须使用:{{(userProfile | async )?.email}} 通过这一行,我可以显示用户的电子邮件地址,但是当我尝试使用console.log时,为什么会出现“Undefined”?

1 个答案:

答案 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-objecthttps://github.com/angular/angularfire2/blob/master/docs/2-retrieving-data-as-objects.md#meta-fields-on-the-object