Hi
I have below Layout Component code. In Dialog Component HTMl i have delete function. Where i need to define & how to delete the record
export class LayoutComponent implements OnInit {
constructor(private _dialog:MatDialog, private dialog: MatDialog){}
openAddEditForm(){
this._dialog.open(EmpAddEditComponent)
}
ngOnInit(): void {
this.getallEmployee();
}
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
}
});
}
}
{{title}}
{{message}}
Jayraj ChhayaPosted Jun 6, 2024, 6:30 AM
You can achieve this by passing data or parameters to the dialog component when opening it from different list components. Here's a step-by-step approach:
Pass Identifier/Context: When opening the dialog component from each list component, pass some identifier or context that identifies the source of the action. This identifier can be a string, an object, or any relevant information.
Receive Data in Dialog Component: In the dialog component, receive the identifier or context passed from the list component. You can do this using Angular's
MatDialogRefandMAT_DIALOG_DATA.Handle Identifier/Context: Use the received identifier or context to determine which list component the action originated from.
Perform Action: Based on the identifier or context, perform the desired action, such as deleting a record from the appropriate list component.
Dialog component
Ramco RamcoPosted Jun 6, 2024, 6:26 AM
Hi Jayraj
If i want to use same Dialog Comonent with multiple List Compnents then how i will know from which component to delete record
Thanks
Jayraj ChhayaPosted Jun 6, 2024, 6:23 AM
To define and handle the delete functionality in the Dialog Component, you need to create the
Delete()function within the Dialog Component class. This function will contain the logic to delete the record when the user confirms the action. Here is an example of how you can define theDelete()function in the Dialog Component:By defining the
Delete()function in the Dialog Component and implementing the necessary delete logic inside it, you can handle the deletion of records effectively when the user interacts with the dialog.