【发布时间】:2018-04-05 21:02:36
【问题描述】:
我正在检索使用 angular fire 的用户列表,如下所示:
this.db.list<IUser>("usersinteam/04f27419-f466-4c5e-9816-fbf120713c4e").valueChanges<IUser>().subscribe(
res => console.log (res),
error => console.log (error),
() => console.log ("complete") );
typescript 中的 IUser 界面如下所示:
export interface IUser{
$key: string,
name: string,
moto: string
}
firebase json 结构如下所示:
{
"04f27419-f466-4c5e-9816-fbf120713c4e" : {
"2b395659-26f4-4c5c-a1b2-fd492d51ff5d" : {
"moto" : "Nah!",
"name" : "Maria"
},
"6b5c19b0-f176-4af1-ab19-ae7ec4c06a5a" : {
"moto" : "Yeah!",
"name" : "David"
},
"ee067245-f085-4c33-acaa-a16deb945cee" : {
"moto" : "wrecking ball",
"name" : "Ian"
}
}
}
我得到一个 IUser 对象列表,其中 name 和 moto 属性正确填充。但是 $key 属性是未定义的。我期待看到 $key 属性设置为每个用户的键。我怎样才能做到这一点?
【问题讨论】:
标签: typescript firebase angularfire