我有以下对象让usersVal = snapshot.val();
console.log
3TngNGbwMVhc5kJ2b3wAULEIP6g1
Object
photoUrl
"https://scontent.xx.fbcdn.net/v/t1.0-1/ss"
provider
"facebook.com"
signup
1480596548396
useremail
"someemail@yahoo.com"
username
"James nan"
__proto__
c834vePyJ3SFVk2iO4rU0ke1cSa2
photoUrl
"https://firebasestorage.googleapis.com/v0/b/ff"
provider
"google.com"
signup
1480600290735
useremail
"3333@gmail.com"
username
"Ericel123eessdd"
__proto__
Object
我想检查对象是否有uid密钥。如果是的话,我将一些boolan值设置为true
this.users = af.database.object('/some-users', { preserveSnapshot: true });
this.users.subscribe(snapshot => {
let usersVal = snapshot.val();
if(key in usersVal){
this.userId = true;
}
});
如何在angular2组件中实现这一目标?
答案 0 :(得分:3)
应该像
一样简单let usersVal = snapshot.val();
if (usersVal["uid"]) {
...
}