我正在尝试使用可观察对象(rxjs 6.5.1)在Angular 9的顶级组件上加载页面数据。当我单独订阅每个服务时,可以看到数据正常返回:
ngOnInit(): void {
const technicianSubscription = this.techniciansClientService.getByTechnicianId(this.technicianId).subscribe(technician => console.log(technician));
const technicianReviewsSubscription = this.technicianReviewsClientService.getByTechnicianId(this.technicianId).subscribe(technicianReviews => console.log(technicianReviews));
}
当我尝试使用forkJoin时,subscribe方法中的数据从未被返回:
ngOnInit(): void {
this.pageDataSubscription = forkJoin({
technician: this.techniciansClientService.getByTechnicianId(this.technicianId),
technicianReviews: this.technicianReviewsClientService.getByTechnicianId(this.technicianId),
}).subscribe(
// data is never logged here
data => console.log(data)
);
}
我已经尝试使用forkJoin传递服务调用的数组,也尝试使用zip,但都没有成功。这里发生了什么?
getByTechnicianId
的调用都正常吗?请检查网络控制台。 - Pankaj Parkar..getById(...).pipe(take(1))
只从此可观察对象中获取一个事件将为您处理此问题。 - Andrei