In Angular How to Run a Loop that hit Back-End one by one

158 Views Asked by At

From Angular When I send some parameter to my Node.js Backend that generate a big array and got some error or timeout issue.

I wanted to send a limited parameter to back end by Loop.

So how to create this Loop that will hit back end -> then get response from back end -> then hit next loop one by one ???

N.B: Previously I create a for loop but that hit all together that didn't meet my need.

My Previous Angular Loop that didn't work well:

for (let i = 0; i < this.branchList.length ; i++) {
         this.form.get('branch_code').setValue(this.branchList[i].branch_code);
        
        this.salSub = 
          this.payrollService.submitForSalaryProcess(this.form.value, 
                                                    this.cycleList)
            .subscribe((data)=> {
                  if (data['isExecuted'] == false) {       
                    this.commonService.showErrorMsg(data['message']);
                  } else {                     
                      this.salProcessList = data['data'];
                  }
                  this.salSub.unsubscribe();                    
            }
          )                 
      };
0

There are 0 best solutions below