使用angularFire和多个子

时间:2018-06-14 15:26:09

标签: angular typescript firebase firebase-realtime-database angularfire2

我正在使用angularFire将我的页面连接到我的数据库。我希望以页面上的列表形式显示存储在我的firebase数据库中的所有用户。我存储这些用户的方式是这样的:

users
  |_date1
  |   |_hour1
  |       |_email:name
  |_date2
  |    |_hour2
  |        |_email:name
  |...

如果我使用下面的方法,我只能得到一个“小节”,而不是其他孩子......

this.fireDB.list('users').snapshotChanges().subscribe(res => {
        res.forEach(doc => {
        this.credentialsArray.push(doc.key, doc.payload.val());
    });
});

我需要将credentialsArrayCredetial模型放在一起,所以我可以将它列在我的表格中:

this.credentialsArray.push(new Credential('name', 'email'));

我也希望得到时间和日期。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

您可以在调用方法之前将数据放在对象Credential中:

this.fireDB.list('users').snapshotChanges().subscribe(res => {
        res.forEach(doc => {
        Credential cred = doc;

        this.credentialsArray.push(cred);
    });
});

检查您的对象是否已准备好检索所有数据类型。

相关问题