I have the following code:
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
}
The problem Im facing is that they all run almost at the same time (simultaneously), while I would like to run a httpClient.post, wait for the response, and then run the next record.
I had this code inside a
processBilling(): void {}
But this does not work even by deleting void
processBilling(): {}
The question is, is it possible for the loop to wait for the httpClient.post response and then move to the next record?
Thanks.