I'm trying to load page data on a top level component in Angular 9 using observables (rxjs 6.5.1). When I subscribe to each of these services individually, I can see the data coming back just fine:
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));
}
When I try to use forkJoin, the data from the subscribe method is never returned:
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)
);
}
I've tried passing forkJoin an array of service calls and I've tried using zip as well, to no avail. What's happening here?
getByTechnicianIdare happening correctly? Check network console. - Pankaj Parkar..getById(...).pipe(take(1))taking just 1 event from this observable will handle the issue for you - Andrei