Angular Modal Service Pattern
Angular Modal Service Pattern
A custom service wraps Angular Material's MatDialog and exposes two semantically distinct methods:
openModal(component, options)— full-width/full-height overlay, reserved for edit and modify actionsopenPopup(component, options)— developer-controlled width/height, used for warnings and secondary overlays stacked on top of an already-open modal
Both methods accept:
- The component to render inside the overlay
- An
optionsobject controllingtitle,subtitle,width/height(popup only),databound to the wrapped component via Angular Material'sMAT_DIALOG_DATAinjectable, anddisableClose(whether outside clicks dismiss the overlay)
The abstraction centralizes dialog configuration and enforces a consistent semantic distinction across the application: modals own the full viewport for significant edits; popups are lightweight and stackable.