tell me the best way to detect the status of several ajax requests in angular8?

You can use the forkJoin operator for your use case in two flavors :

1 – In your component constructor or ngOnInit do the following :

forkJoin(
  {
    candidateBasic: this.candidateService.getBasic(candidatePersonalInfo.id),
    experienceList: this.candidateService.getExperience(candidatePersonalInfo.id), 
    educationList: this.candidateService.getEducation(candidatePersonalInfo.id),
    certificationList: this.candidateService.getCertification(candidatePersonalInfo.id),
    candidateAbout : this.candidateService.getAbout(candidatePersonalInfo.id)
  }
)
.subscribe(e => this.selectedCandidateData = e)

And in your template use selectedCandidateData variable instead of selectedCandidateDataLoaded()

Or

2 – write directly the forkJoin inside selectedCandidateDataLoaded() method and don’t subscribe.

selectedCandidateDataLoaded() : Observable<Candidate> {
   return forkJoin({...});
}

In your template use async pipe like :

*ngIf="selectedCandidateDataLoaded() | async"

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top