I have to Send Multiple Post request with same URL but different payload and to check status of each request, if its failed or success. and then i want to check data variable with all recored like 1 failed 2 success , with below code its not working
let id = [123,345,456];
let data = [];
id.foreach(payload=>{
let keyResponse = [{
status: ""
}];
this.restService.post('test/api',payload).subscribe(
(output: any) => {
keyResponse[0].status = "SUCCESS" ;
data.push(keyResponse[0]);
},
err => {
keyResponse[0].status = "ERROR" ;
data.push(keyResponse[0]);
}
);
});
console.log(data);
HttpClient.post, it does not have to be an object. You might be mistaking it forHttpClient.get, where payload needs to be an object, under theparamsoption.