Skip to main content
added 4 characters in body
Source Link
wentjun
  • 42.8k
  • 10
  • 107
  • 116

Since you are using Angular, you can make use of RxJS operators to handle this scenario. The forkJoin operator will allow you to wait for the while loop operation to be completed before returning all the observables.

This is how you can make use of the operator:

testingFunction() {
   let i: number = 0;
   const observablesList = []; 

   while(i < 20){
     observablesList.push(this.testService.getAll());
     i++;
   }
   forkJoin(observablesList).subscribe((response) => {
     console.log(response);
   });
}

Since you are using Angular, you can make use of RxJS operators to handle this scenario. The forkJoin operator will allow you to wait for the while loop operation to be completed before returning all the observables.

This is how you can make use of the operator:

testingFunction() {
   let i: number = 0;
   const observablesList = []; 

   while(i < 20){
     observablesList.push(this.testService.getAll());
     i++;
  }
  forkJoin(observablesList).subscribe((response) => {
    console.log(response);
  });
}

Since you are using Angular, you can make use of RxJS operators to handle this scenario. The forkJoin operator will allow you to wait for the while loop operation to be completed before returning all the observables.

This is how you can make use of the operator:

testingFunction() {
   let i: number = 0;
   const observablesList = []; 

   while(i < 20){
     observablesList.push(this.testService.getAll());
     i++;
   }
   forkJoin(observablesList).subscribe((response) => {
     console.log(response);
   });
}
Source Link
wentjun
  • 42.8k
  • 10
  • 107
  • 116

Since you are using Angular, you can make use of RxJS operators to handle this scenario. The forkJoin operator will allow you to wait for the while loop operation to be completed before returning all the observables.

This is how you can make use of the operator:

testingFunction() {
   let i: number = 0;
   const observablesList = []; 

   while(i < 20){
     observablesList.push(this.testService.getAll());
     i++;
  }
  forkJoin(observablesList).subscribe((response) => {
    console.log(response);
  });
}