I'm using ng-zorro components in my project, and I want to show a model that calls a service to delete an entry, this is how I defined the delete confirm dialog :
showDeleteConfirm(id: string): void{
this.modal.confirm({
nzTitle: 'Êtes-vous sûr de vouloir supprimer ce enregistrement ?',
nzOnOk: () => {
this.service.delete(id).subscribe(data => {
this.notification.create("success", "Suppression", "L'enregistrement a été supprimée !");
});
}
});
}
But I had this issue where the code inside the subscribe function is executed multiple times.
How can I solve this ?
Edit:
This is my delete function :
delete(id: string): any{
return this.http.delete<Entity>(this._apiURL + id, this.httpOptions).pipe(
catchError(this.handleError)
);
}
private handleError(err: HttpErrorResponse) {
let errorMessage = '';
if (err.error instanceof ErrorEvent) {
errorMessage = `An error occurred: ${err.error.message}`;
} else {
errorMessage = `Server returned code: ${err.status}, error message is: ${err.message}`;
}
return errorMessage;
}
deletefunction.