Below is the code I am using:
for (let member of this.pendingBilling) {
//start billing
let payLoad: any = {};
payLoad.credentials = this.credentials
payLoad.data = {
memberid: member.memberid,
payid: member.payid
}
var APIURL = globals.endpoint + "members/rb";
let options = { headers: new HttpHeaders().set('Content-Type', 'application/json') };
let body: any = payLoad;
this.httpClient.post(APIURL, JSON.stringify(body), options).subscribe(
result => {
let apiResponse: any = result;
if (apiResponse.success == 1) {
member.status = apiResponse.status
member.amount = apiResponse.amount
}
if (apiResponse.success == 0) {
member.status = apiResponse.status
}
},
error => {
member.status = 91
});
//end billing
}
I am encountering an issue where all the operations are running almost simultaneously, but I would like each httpClient.post to wait for a response before proceeding to the next record.
I attempted placing this code within a
processBilling(): void {}
However, even after removing 'void,' it did not work. Another attempt was made with:
processBilling(): {}
My question remains: Is there a way for the loop to pause for the httpClient.post response before moving on to the next record?
Appreciate your help.