When I click the delete button it will delete all the products with zero quantity. I add an alert message to notify the user if the table has zero quantity or not. The success message will alert after deleting all the products with zero quantity and the error message alert if the table has no zero quantity. I’m using the sweetalert2. The problem is when I deleted all products that have zero quantity the error message showed instead of the success message. I want to show the success message after I deleted products and the error message only shows if the table has no zero quantity. How can I alert the success after I deleted all the products with zero quantity?
//Delete all row with zero quantity
public onDeleteProduct(): void {
this.productServive.deleteProduct().subscribe(
(response: void) => {
console.log(response);
this.messageShow();
this.getAllProduct();
this.onCloseUpdateHandled();
},
(error: HttpErrorResponse) => {
this.errorMessage(error.message);
}
);
}
// search if the product quantity is zero or not
public messageShow(): void {
for(const product of this.products) {
if(product.quantity === 0) {
this.successMessage("deleted");
} else {
this.errorMessage("No more out-of-stock");
}
}
}
//html
<button type="button" class="btn btn-outline-danger btn-sm" (click)="onDeleteProduct()">Delete</button>
//example table
enter image description here
