在收集公司中,有一个带有模型的文件
company: example
address: nowhere
users:{
123456789:{
email: qwerty@example.com
}
}
其中123456789是用户的ID
从文件中获取数据
this.compColl = this.afs.collection('companies');
this.comp = this.compColl.valueChanges();
列出视图中的数据
<li *ngFor="let cmp of comp | async">{{cmp.company}}</li>
这适用于公司和地址,但不适用于
<li *ngFor="let cmp of comp | async">{{cmp.email}}</li>
如何列出本文档中的用户电子邮件
答案 0 :(得分:0)
users:{
123456789:{
email: qwerty@example.com
}
}
如果您想获得qwerty@example.com
,可以使用
<li *ngFor="let cmp of comp | async">{{cmp.users[123456789].email}}</li>
用户是一个对象,而不是一个数组,因此您无法使用<li *ngFor="let user of comp.users | async">{{user.email}}</li>
。如果你想使用它,你的数据库应该返回如下内容:
company: example
address: nowhere
users:[ //instead of {
123:{
email: qwerty@example.com
},
456:{
email: qwerty@example.com
},
] //instead of }