如何使用 angularFire 而没有 "key" 从 firebase 数据库中检索用户列表?
How to retrieve a list of users from firebase database with angularFire and no "key"?
我正在使用 angularFire 将我的页面连接到我的数据库。我想在页面上以列表的形式显示存储在我的 firebase 数据库中的所有用户。我存储这些用户的方式是通过他们的电子邮件,如下所示:
users
|_email:name
|
|_email:name
|
|_email:name
|
|_...
我面临的问题是我不知道如何检索所有用户并放入数组。
我认为它类似于 .list()
,但在这个问题中我需要以不同方式分隔用户,例如:
user
|_key1
| |_email:value
| |_name:value
|_key2
| |_email:value
| |_name:value
|_...
我需要用 Credetial
模型将它放入我的 credentialsArray
中,这样我就可以将它列在我的 table:
中
this.credentialsArray.push(new Credential('name', 'email'));
因为我是这样列出的:
<tr *ngFor="let item of credentialsArray">
<td>{{ item.name }}</td>
<td>{{ item.email }}</td>
</tr>
我该怎么做?
从 'user' 列表中,您可以使用如下循环将检索到的值推送到数组中:
this.fireDB.list('user').snapshotChanges().subscribe(res => {
res.forEach(doc => {
this.credentialsArray.push(doc.payload.val());
});
});
那么您的 html 代码就可以很好地显示结果。
我正在使用 angularFire 将我的页面连接到我的数据库。我想在页面上以列表的形式显示存储在我的 firebase 数据库中的所有用户。我存储这些用户的方式是通过他们的电子邮件,如下所示:
users
|_email:name
|
|_email:name
|
|_email:name
|
|_...
我面临的问题是我不知道如何检索所有用户并放入数组。
我认为它类似于 .list()
,但在这个问题中我需要以不同方式分隔用户,例如:
user
|_key1
| |_email:value
| |_name:value
|_key2
| |_email:value
| |_name:value
|_...
我需要用 Credetial
模型将它放入我的 credentialsArray
中,这样我就可以将它列在我的 table:
this.credentialsArray.push(new Credential('name', 'email'));
因为我是这样列出的:
<tr *ngFor="let item of credentialsArray">
<td>{{ item.name }}</td>
<td>{{ item.email }}</td>
</tr>
我该怎么做?
从 'user' 列表中,您可以使用如下循环将检索到的值推送到数组中:
this.fireDB.list('user').snapshotChanges().subscribe(res => {
res.forEach(doc => {
this.credentialsArray.push(doc.payload.val());
});
});
那么您的 html 代码就可以很好地显示结果。