Angular 9: forkJoin subscribe not working

Published

I’m trying to load page data on a top level component in Angular 9 using observables. 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?

Source: Angular Questions

Published
Categorized as angular, angular9, javascript, observable, rxjs Tagged , , , ,

Answers

newer version try to use as array forkJoin([ technician: this.techniciansClientService.getByTechnicianId(this.technicianId),
technicianReviews: this.technicianReviewsClientService.getByTechnicianId(this.technicianId) ]).


Saswat Mohapatra

forkJoin([technician: this.techniciansClientService.getByTechnicianId(this.technicianId),
technicianReviews: this.technicianReviewsClientService.getByTechnicianId(this.technicianId)]);

newer version angular 9 onwards use array of observables as parameters.


Saswat Mohapatra

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq