Hi
Before deleting record in i wan to get confirmarion in popup whether user wants to delete record or not. If yes only then record should be deleted
Thanks
Hi
Before deleting record in i wan to get confirmarion in popup whether user wants to delete record or not. If yes only then record should be deleted
Thanks
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
Naimish MakwanaRank #324 · 7.7K reputationPosted May 9, 2024, 7:34 AM EDT
To get a confirmation from the user before deleting a record, you can use Angular’s built-in
window.confirm()method. This method displays a dialog box with a specified message, along with an OK and a Cancel button.Here’s a basic example of how you might implement this:
deleteRecord(record) { const confirmation = window.confirm('Do you really want to delete the record?'); if (confirmation) { // Code to delete the record goes here } }In this example,
window.confirm()will display a dialog box with the message ‘Do you really want to delete the record?’. If the user clicks OK,window.confirm()will returntrueand the record will be deleted. If the user clicks Cancel,window.confirm()will returnfalseand the record will not be deleted.Thanks
Jayraj ChhayaRank #304 · 8.2K reputationPosted May 9, 2024, 8:09 AM EDT
To achieve this functionality in Angular, you can utilize Angular Material Dialog component to create a modal popup for confirmation. Here's a basic implementation example:
import { Component } from '@angular/core'; import { MatDialogRef } from '@angular/material/dialog'; @Component({ selector: 'app-confirmation-dialog', templateUrl: './confirmation-dialog.component.html', }) export class ConfirmationDialogComponent { constructor(public dialogRef: MatDialogRef) {} confirmDelete(): void { this.dialogRef.close(true); // User confirmed deletion } cancelDelete(): void { this.dialogRef.close(false); // User canceled deletion } }import { MatDialog } from '@angular/material/dialog'; import { ConfirmationDialogComponent } from './confirmation-dialog/confirmation-dialog.component'; constructor(private dialog: MatDialog) {} openConfirmationDialog(): void { const dialogRef = this.dialog.open(ConfirmationDialogComponent); dialogRef.afterClosed().subscribe((result) => { if (result) { // Proceed with deletion // Call your delete record function here } else { // User canceled deletion } }); }By following these steps, you can implement a modal popup for confirmation before deleting a record in Angular using Angular Material Dialog.
Jignesh KumarRank #91 · 22.9K reputationPosted May 9, 2024, 12:35 PM EDT
Hello Ramco,
You can create as below in a simple way, Add div for confirmation model pop up in your html,
Add the below methods in your component,
public itemIdToDelete : number = 0; // This field to set itemToDelete which stores ID // Method to open the confirmation modal openConfirmationModal(itemId: number) { // Code to set your Id $('#confirmationModal').modal('show'); // Assuming you're using Bootstrap modal } // Method to handle delete confirmation confirmDelete() { // Code to delete the item based on Id // Call your delete method here or perform deletion logic // Example: this.deleteItem(this.itemIdToDelete); $('#confirmationModal').modal('hide'); // Close the modal after deletion } // Method to delete the item onDelete(itemId: number) { // Set the id to delete here and then open the confirmation modal this.itemIdToDelete = itemId; this.openConfirmationModal(); }Ramco RamcoRank #462 · 5.4K reputationPosted May 10, 2024, 12:08 AM EDT
Hi Jignesh
I am getting error Cannot find name $. Do you need to install type definitions for Jquery.
Thanks