Hi
In below code i want when user clicks Delete it should ask for confirmation in Modal Form.
I don't want to use confirm()
Code
Action
edit
deleteThanks
Hi
In below code i want when user clicks Delete it should ask for confirmation in Modal Form.
I don't want to use confirm()
Action
edit
deleteThanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jayraj ChhayaRank #304 · 8.2K reputationPosted Jun 5, 2024, 5:19 AM EDT
To achieve this functionality without using the
confirm()function, you can create a custom confirmation modal using Angular Material Dialog. Here's a basic implementation:ng generate component ConfirmationDialogImplement the confirmation dialog component with the necessary content and buttons for confirmation.
In your component where the delete button is located, inject the
MatDialogservice and open the confirmation dialog when the delete button is clicked:import { MatDialog } from '@angular/material/dialog'; import { ConfirmationDialogComponent } from 'path-to-your-confirmation-dialog-component'; constructor(private dialog: MatDialog) {} openConfirmationDialog(): void { const dialogRef = this.dialog.open(ConfirmationDialogComponent, { width: '250px', data: { message: 'Are you sure you want to delete?' } }); dialogRef.afterClosed().subscribe(result => { if (result) { // Perform delete action here } }); }openConfirmationDialog()function when the delete button is clicked: