首页 > 解决方案 > firestore 文档中的未定义字段

问题描述

使用这个医生集合在此处输入图像描述 ,我想在组件类中获取字段医生名称的值。

我试过这样:

export class EditDoctorComponent implements OnInit { 
doctorName :any;
...
 ngOnInit(): void {
    const doctorID = this.act.snapshot.paramMap.get('id');
    this.db.collection("doctors").doc(doctorID)
    .valueChanges()
    .subscribe( (res :any) => {
     this.doctorName = res.doctorName;
     console.log('Name = ' + this.doctorName);
    })

}

在控制台中,我收到结果未定义。我感谢任何帮助或指导。谢谢!

标签: angulargoogle-cloud-firestore

解决方案


推荐阅读