Javascript 组合两个angularFire(实时数据库)列表对象以形成新的可观察对象
我有两个可以观察到的病人和预约。预约包括病人。我希望获取所有预约数据和相应的患者数据,并将它们合并,形成新预约患者[]可观察。下面的代码在HttpClient上运行良好,但当我更新为使用AngularFire时,它就不再工作了Javascript 组合两个angularFire(实时数据库)列表对象以形成新的可观察对象,javascript,angular,firebase-realtime-database,rxjs,angularfire2,Javascript,Angular,Firebase Realtime Database,Rxjs,Angularfire2,我有两个可以观察到的病人和预约。预约包括病人。我希望获取所有预约数据和相应的患者数据,并将它们合并,形成新预约患者[]可观察。下面的代码在HttpClient上运行良好,但当我更新为使用AngularFire时,它就不再工作了 getAppointments() { this.appointmentService.fetchAllAppointments() .pipe( take(1), switchMap(appointments => {
getAppointments() {
this.appointmentService.fetchAllAppointments()
.pipe(
take(1),
switchMap(appointments => {
const appointedPatients: AppointedPatient[] = [];
for (const appointment of appointments) {
const appointmentDate = new Date(appointment.appointmentDateTime);
const appointmentDateOnly = new Date(appointmentDate.setHours(0, 0, 0, 0));
const newAppointment$: any = this.patientsService.getPatient(appointment.patientId)
.pipe(
switchMap((patient) => of(new AppointedPatient(
appointment.appointmentId,
patient.firstName,
patient.lastName,
patient.address,
patient.casePaperNumber,
patient.mobileNumber,
appointment.appointmentDateTime,
appointmentDateOnly
))
)
);
appointedPatients.push(newAppointment$);
}
return forkJoin(appointedPatients);
})
).subscribe(data => console.log(data));
}
代码看起来很好是的。。。但是在订阅之后,什么都没有发生。。它甚至不会将null打印到控制台。。。如果您有任何其他方法来处理此类场景,请在switchMap内的不同位置共享设置断点,并查看是否实际执行了源可观察对象。然后深入观察forkJoin项目,检查是否正确获取预约和患者。。。它也得到了新的约会$observable。。。无法判断是否正确?请尝试返回forkJoin(appointedPatients).pipe(tap(console.log),catchError(e=>{console.error(e);返回(e)}),可能有错误