我需要帮助来了解如何在Angular中进行模式确认后触发删除API。
onDelete(id:number){
this.confirmationDialogService.confirm('Confirm Delete', 'Do you really want to delete this document?')
.then(() => this.employeeService.deleteEmployee(id)) //this is not working
//.catch(() => console.log('User dismissed the dialog (e.g., by using ESC, clicking the cross icon, or clicking outside the dialog)'));
/*if (confirm('Are you sure you want delete this record?') == true) {
this.employeeService.deleteEmployee(id);
}*/
}
您可以在代码中看到。单击模式中的“确定”按钮后,我需要知道如何调用delete API。
答案 0 :(得分:0)
尝试使用{}
中的括号.then
来使用多行代码,如下所示-
public openConfirmationDialog(id) {
this.confirmationDialogService.confirm('Please confirm..', 'Do you really want to ... ?')
.then((confirmed) => {
this.employeeService.deleteEmployee(id);
console.log('User confirmed:', confirmed);
})
.catch(() => console.log('User dismissed the dialog (e.g., by using ESC, clicking the cross icon, or clicking outside the dialog)'));
}
答案 1 :(得分:0)
onDelete(id:number){
data.table
}