angular - 使用 Angular Firestore 获取数据
问题描述
我是 Angular Firestore 的新手,我正在尝试从 Firestore 获取数据。我有以下代码:
import { AngularFirestore } from '@angular/fire/firestore';
export class ProfileComponent implements OnInit {
myArray: any[] = []
constructor(private authService: AuthService, public afs: AngularFirestore) {}
test = this.afs.collection('doctors').get().subscribe((ss) => {
ss.docs.forEach((doc) => {this.myArray.push(doc.data()); });
});
}
在我的 html 文件中,我试图像这样显示 myArray:
<li *ngFor='let doc of myArray'>
{{doc}}
</li>
我知道我的数组在我的 firebase 中正确读取了表“医生”,因为它打印了三个对象,这是我的医生表中的元素数量,但我在 html 中得到以下输出:
有人可以帮我正确显示这些值吗?餐桌医生有电子邮件、名字和姓氏。我想打印每个实体的电子邮件。
解决方案
您需要使用json
管道显示数据,如下所示:
<li *ngFor='let doc of myArray'>
{{doc | json}}
</li>
当json
你想显示一个对象时,管道是必需的,它主要用于调试。文档中的更多信息:
Angular - JsonPipe
推荐阅读
- postgresql - 在架构上创建的 Postgres 表在 Public 下可见 - 我该如何防止这种情况?
- java - 使用 JAVA 进行 RSA 加密/解密
- c - 尝试在 CS50 中为 PSET4 的图像实现框模糊时,为什么我的 RGB 值略有偏差?
- php - 函数 App\Http\Controllers\VehicleController::show(), -Laravel 的参数太少
- react-native - HomeStack React Navigator V5中的按钮到下一页的问题
- telnet - 如何通过 telnet(或其他工具)在消息中间发送 \r\n
- ffmpeg - 编译 ffmpeg Ubuntu 16
- mongodb - 对MongoDB中文档内的数组元素进行排序?
- node.js - 为什么使用令牌和密钥
- xml - 如何在 Coldfusion 中将数组添加到 XML 对象?