Issue
this.hobbies :any[]=[];
this.worklist : any[]=[];
forkJoin(this.personService.addHobbies(this.hobbies),this.professionService.updateWorks(this.worklist))
.subscribe(res => {});
here i'm calling 2 apis this.personService.addHobbies(this.hobbies) and this.professionService.updateWorks(this.worklist) with forkJoin, but i want to avoid api call this.personService.addHobbies() if this.hobbies is empty list.. only this.professionService.updateWorks(this.worklist) should call if this.worklist is not empty list. Is there any solution to avoid that particular api call if list is null or empty.. Please help
Solution
You can use an array in which you add your API calls :
this.hobbies: any[] = [];
this.worklist: any[] = [];
const requests = [];
if (this.hobbies.length > 0){
requests.push(this.personService.addHobbies(this.hobbies));
}
if (this.worklist.length > 0) {
requests.push(this.professionService.updateWorks(this.worklist));
}
forkJoin(requests).subscribe(res => {});
Answered By - MaisOuEtDoncOrNiCar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.