Description : I called an HTTP request inside for loop.I want to get the response from service file then increase loop.How can i wait to get response from service file then execute loop.
for(let i=0;i<final_arr.length;i++)
{
this.user.list_upload(JSON.stringify(ins_arr)).subscribe(data=>{
if(data.hasOwnProperty('STATUS'))
{ if(data.STATUS.toLowerCase()=='success')
{
this.update();
}
else if(data.STATUS.toLowerCase() == 'error')
{
this.user.showToast(data.MESSAGE);
}
}
},err=>{
this.user.showToast("Error occurred in service file");
});
}
Please advise
You should use an async function. First convert the HTTP request to a promise, then call that promise asynchronously inside the for loop: