【发布时间】:2015-11-08 10:45:08
【问题描述】:
Firebase 具有 $onAuth 方法,用于侦听客户端身份验证状态的更改。如果客户端通过身份验证,回调将传递一个包含 uid 的对象。 这是我的问题: 根据这个 uid,我怎样才能得到这个对象的 $id。
这就是我的数据在 firebase 中的样子:
profile {
-K2a7k9GXodDriEZrM3f {
email: "ale@aol.com"
gravatar: "https://www.gravatar.com/avatar/1d52da55055f0c8..."
uid: "3f9e0d53-4e61-472c-8222-7fc9f663969e"
name: "ale"
}
}
我正在使用
auth.$onAuth(function (authData) {
if (authData) {
authData.profile = //here I want the $id of the object
}
})
我看到我可以对 authData 响应做的就是使用以下方法获取对象的 uid:
$firebaseObject(ref.child('profile').child(authData.uid));
此 authData 不包含对象的 $id(即 -K2a7k9GXodDriEZrM3f)。这就是我正在寻找的,以便让用户的信息可用。有没有办法做到这一点?
谢谢。
【问题讨论】:
-
$id 是 $firebaseArray 记录的属性,在 $firebaseObject 实例中不存在。如果您想要 $firebaseObject 实例的密钥(不是 OP 在这里寻找的),可以在 obj.$ref().key() 中找到。
标签: angularjs firebase angularfire firebase-authentication