I am working on Angular 7 and looking to develop common component or service to show Alerts/Dialog Box when User Confirming/Deleting details on button click.
I went through link: https://firstclassjs.com/create-a-reusable-confirmation-dialog-in-angular-7-using-angular-material/ and on web I found the many people are using Angular Material way to implement.
Is there any simple way to dynamically pass the title
and message
to alert service or component based on action like Update/Delete you're performing?
In app.component.ts you need to extend
openDialog()
like this:And extend (app.component.html) like this:
Good luck!
I assume you follow the link you provided.
confirmDialogService
openDialog$: Subject<{title: string, message: string}> = new Subject<{title: string, message: string}>();
openConfimDialog(string message, string title) { this.openDialog$.next({title, message}) };
openDialog()
method from link you provided and also pass message and title to the dialogat this point you should be able to see the dialog will be opened.
next step is to receive if the user confirm or cancel dialog.
use the same pattern to have another observable
afterClosed$
in service and a method to callednotifyDialogClosed
now this time call
notifyDialogClosed
from app.component and subscribe toafterClosed$
in your component, just don't forget to unsubscribeIf you create stackblitz of that link you provided I can help you for the rest