I wanna call a delete api for each selected customer. I am using one service layer. so when I call the service with the selected custoer code then the customer will be deleted.
In AngularJS I used $.allSettled which will give callbacks for fullfilled and not full filled. I can insert the success and failed customer deletions and I can show in UI about succeeded list and failed list.
$q.allSettled(promises)
.then(function(results) {
results.forEach(function(result) {
if (result.state === 'fulfilled') {
// success :)
} else {
// failed :(
//result.reason.config.data contains api input data
}
});
}).finally(function() {
});
this.promises = [];
//FORMING LIST OF PROMISES
this.customerList.forEach(code => {
this.promises.push(this.customersservice.delete(code));
});
Promise.all(this.promises).then(values => {
console.log(values);
}).catch(reason => {
//here i need to catch every time an api call fails for some reason , so that I can show in UI
console.log(reason)
});
//SERVICE
delete(code: string): Observable<any> {
return this.http.delete(`${this.baseURL}/` + code)
}
How to achieve this in angular2+