Angular Modal Component | ng-hub-ui-modal

Accessible Angular modal component with stacking, fullscreen mode, templates, keyboard handling and CSS variables for standalone apps.

API reference

Here's the full contract for modal: everything you can bind, listen to, project and theme, gathered in one place. Wire up what you need and style what you want — it's standalone and signal-friendly.

Inputs

Dial modal in with 14 inputs. Bind them like any Angular @Input.

NameTypeDefaultDescription
animationbooleanIf true, modal opening and closing will be animated. Default: true
backdropboolean | "static"If true, the backdrop element will be created. Alternatively, specify "static" for a backdrop which doesn't close the modal on click. Default: true
centeredbooleanIf true, the modal will be centered vertically. Default: false
placementHubModalPlacementControls where the modal is placed within the viewport. Default: HubModalPlacement.Center
keyboardbooleanIf true, the modal will be closed when Escape key is pressed. Default: true
closeOnNavigationbooleanIf true, the modal will be closed when the user navigates back in browser history (history.back(), browser back button). Default: true
size"sm" | "lg" | "xl" | stringSize of the modal window
windowClassstringA custom class to append to the modal window
backdropClassstringA custom class to append to the modal backdrop
dismissSelectorstringCustom selector for elements that can trigger the dismissal of the modal window. Default: "[data-dismiss=\"modal\"]"
closeSelectorstringCustom selector for elements that can trigger the closing of the modal window. Default: "[data-close=\"modal\"]"
headerSelectorstringCustom selector for the header element of the modal window
footerSelectorstringCustom selector for the footer element of the modal window
dataanyAdditional data that needs to be passed to the modal window when it is opened

Outputs

React to what modal does — 1 events to hook your logic onto.

NameTypeDescription
dismissanyEmitted by the modal window when the user dismisses the modal, e.g. by pressing Escape, clicking the backdrop, or activating the built-in close button. The payload is the dismiss reason (ModalDismissReasons.ESC, ModalDismissReasons.BACKDROP_CLICK, or a custom value).

Methods

Drive modal from code — 17 methods on its programmatic surface.

NameSignatureReturnsDescription
HubModal.openopen<C, R, D>(content: Type<C> | TemplateRef<any> | string, options?: HubModalOptions<D>): HubModalRef<C, R>HubModalRef<C, R>Opens a new modal window with the given content (component type, TemplateRef, or string) and options, and returns a HubModalRef to control it. Content components can inject HubActiveModal and the HUB_MODAL_DATA token to interact with the modal and read the data payload.
HubModal.dismissAlldismissAll(reason?: any): voidDismisses all currently displayed modal windows with the supplied reason.
HubModal.hasOpenModalshasOpenModals(): booleanbooleanIndicates if there are currently any open modal windows in the application.
HubModal.activeInstancesactiveInstances: EventEmitter<HubModalRef[]>EventEmitter<HubModalRef[]>Event emitter that emits the list of currently open HubModalRef instances every time a modal is opened or removed.
HubModalRef.closeclose(result?: R): voidCloses the modal with an optional result value. The HubModalRef.result promise is resolved with the provided value.
HubModalRef.dismissdismiss(reason?: any): voidDismisses the modal with an optional reason value. The HubModalRef.result promise is rejected with the provided value. Honours the beforeDismiss guard when one was configured.
HubModalRef.updateupdate(options: HubModalUpdatableOptions): voidUpdates options of an opened modal (aria attributes, centered, placement, fullscreen, backdropClass, size, variant, windowClass, modalDialogClass).
HubModalRef.componentInstancecomponentInstance: C | voidC | voidThe instance of the component used as modal content. Returns undefined when a TemplateRef was used as content or when the modal is closed.
HubModalRef.resultresult: Promise<R>Promise<R>Promise resolved with the close result when the modal is closed and rejected with the dismiss reason when it is dismissed.
HubModalRef.closedclosed: Observable<R>Observable<R>Observable that emits the result passed to close() when the modal is closed.
HubModalRef.dismisseddismissed: Observable<any>Observable<any>Observable that emits the dismiss reason when the modal is dismissed — the value passed to dismiss(), or an internal reason such as backdrop click or Escape.
HubModalRef.shownshown: Observable<void>Observable<void>Observable that emits and completes once the modal is fully visible and its opening animation has finished.
HubModalRef.hiddenhidden: Observable<void>Observable<void>Observable that emits and completes once both the modal window and the backdrop are hidden, animations finished, and their elements removed from the DOM.
HubActiveModal.closeclose(result?: R): voidCloses the modal hosting the content component, resolving the HubModalRef.result promise with the optional result value.
HubActiveModal.dismissdismiss(reason?: any): voidDismisses the modal hosting the content component, rejecting the HubModalRef.result promise with the optional reason value.
HubActiveModal.updateupdate(options: HubModalUpdatableOptions): voidUpdates options of the opened modal from inside the content component.
HubActiveModal.datadata: DDThe typed payload passed through HubModalOptions.data. Equivalent to injecting the HUB_MODAL_DATA token; resolves to null when no data option was provided.

Templates

Make it yours — 1 template slots let you project custom markup.

NameDescriptionExample
Modal TemplateTemplate reference that can be passed to the modal service<ng-template #modalTemplate let-close="close" let-dismiss="dismiss"> <div class="modal-header"> <h4 class="modal-title">Modal Title</h4> </div> <div class="modal-body"> Modal content goes here </div> <div class="modal-footer"> <button class="btn btn-secondary" (click)="dismiss()">Cancel</button> <button class="btn btn-primary" (click)="close('result')">OK</button> </div> </ng-template>