
Product
Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.
@webileapps/ngx-modal-dialog
Advanced tools
Dynamic modal dialog for Angular that does not sit on DOM waiting to be triggered, but rather gets injected upon need.
Made with Bootstrap 4 styles in mind, but configurable to any framework or custom set of styles. Simple demo can be found here.
This documentation is for version 3.x.x and Angular 6+. If you are using older version of Angular (v2-v5) please use previous version.
npm install --save ngx-modal-dialog
Modal dialog uses ComponentFactoryResolver to inject the given child component to the dialog.
ModalDialogService makes sure that only one instance of a modal dialog is opened at a time.
With IModalDialogOptions you can define which component will be rendered inside the dialog and configure it based on your needs.
You can further use action buttons to control modal dialog from external component or child component. If action performed on button click is successful, modal dialog will close. Otherwise it will alert user.
Ngx-modal-dialog is intended to be used with Bootstrap 4, however you can apply your custom styles from your desired UI framework by providing class names in IModalDialogSettings.
ngx-modal module in your application at any place. The recommended way is to add forRoot initialization in the main app module.import { BrowserModule } from '@angular/platform-browser';
import { ModalDialogModule } from 'ngx-modal-dialog';
@NgModule({
imports: [
BrowserModule,
ModalDialogModule.forRoot()
],
bootstrap: [AppComponent]
})
export class AppModule { }
IModalDialog or use the SimpleModalDialog as a child component.Custom component should be inserted into both declarations and entryComponents in the NgModule they are part of. entryComponents has to be used since component is dynamically inserted onto the page and Angular is not aware of it.
ModalDialogService where you want to open the dialog. Call openDialog passing parent ViewContainerRef and partial IModalDialogOptions object:constructor(modalService: ModalDialogService, viewRef: ViewContainerRef) { }
openNewDialog() {
this.modalService.openDialog(this.viewRef, {
title: 'Some modal title',
childComponent: SimpleModalComponent
});
}
actionButtons in modal dialog options or child component to control modal dialog.class MyModalComponent implements IModalDialog {
actionButtons: IModalDialogButton[];
constructor() {
this.actionButtons = [
{ text: 'Close' }, // no special processing here
{ text: 'I will always close', onAction: () => true },
{ text: 'I never close', onAction: () => false }
];
}
dialogInit(reference: ComponentRef<IModalDialog>, options: Partial<IModalDialogOptions<any>>) {
// no processing needed
}
}
Action button can be of two types:
truthful (true, successful Promise or Observable) than it will close the dialogfalsy (false, rejected Promise or failed Observable) it will trigger alert style and not close the dialog.openDialog(target: ViewContainerRef, options: Partial<IModalDialogOptions<T>> = {}): Closes existing and opens a new modal dialog according to IModalDialogOptions.
T represents a type of options data field. If you don't care about strong typing just pass any.Every component that is used as modal dialog must implement IModalDialog.
dialogInit(reference: ComponentRef<IModalDialog>, options: Partial<IModalDialogOptions<any>>) => void
Mandatory: true
Default: -
This method is called after initialization of child component. Purpose of the method is to pass necessary information from outer scope to child component.actionButtons
Mandatory: false
Default: -
Type: string
Modal heading textinterface IModalDialogOptions<T> {
title: string;
childComponent: IModalDialog;
onClose: ModalDialogOnAction;
actionButtons: IModalDialogButton[];
data: T;
placeOnTop: boolean;
settings: IModalDialogSettings;
closeDialogSubject: Subject<void>;
}
This is generic interface, where T is arbitrary type of data section.
title: string
Modal heading text
childComponent: any
Component type that will be rendered as a content of modal dialog. Component must implement IModalDialog interface.
onClose(): ModalDialogOnAction
Function to be called on close button click. In case of Promise and Observable, modal dialog will not close unless successful resolve happens. In case of boolean, modal dialog will close only if result is truthful.
actionButtons: Array<IModalDialogButton>
Footer action buttons for control of modal dialog. See IModalDialogButton.
Action buttons defined in child component have priority over action buttons defined via options.
Action buttons close the modal dialog upon successful operation.
data: T
Arbitrary data that will be passed to child component via dialogInit method.
placeOnTop: boolean
Flag stating whether opening the modal dialog should close all the other modal dialogs, or modal should be rendered on top of existing ones.
settings: IModalDialogSettings
Additional settings for granular configuration of modal dialog. See IModalDialogSettings.
closeDialogSubject:Subject<void>
Custom modal closing subject. Can be used to manually trigger modal dialog close from within the child component.
interface IModalDialogButton {
text: string;
buttonClass?: string;
onAction?: ModalDialogOnAction;
}
stringstringbtn btn-primaryPromise<any> | Observable<any> | booleantruthful.type ModalDialogOnAction = () => Promise<any> | Observable<any> | boolean | void;
Function returning Promise, Observable, boolean or no value. Modal dialog will close automatically if return of action is:
trueAction button will initiate alert behavior if return is:
falseIf action button returns void, there are no side effects.
interface IModalDialogSettings {
overlayClass: string;
overlayAnimationTriggerClass: string;
modalClass: string;
modalAnimationTriggerClass: string;
contentClass: string;
headerClass: string;
headerTitleClass: string;
closeButtonClass: string;
closeButtonTitle: string;
bodyClass: string;
footerClass: string;
alertClass: string;
alertDuration: number;
buttonClass: string;
notifyWithAlert: boolean;
}
stringmodal-backdrop fade showstringshowstringmodal fade ngx-modalstringshowstringmodal-dialog modal-dialog-centeredstringmodal-contentstringmodal-headerstringmodal-titlestringclose glyphicon glyphicon-removestringCLOSEstringmodal-bodystringmodal-footerstringngx-modal-shakenumber250stringbtn btn-primarynumbertrueLicensed under MIT
FAQs
Dynamic modal dialog for Angular
We found that @webileapps/ngx-modal-dialog demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.

Research
More than 140 Mastra npm packages were compromised in a supply chain attack that used a typosquatted dependency to deliver a cross-platform infostealer during installation.

Research
/Security News
A new npm package tests AI malware scanners with prompt injection, safety-triggering comments, context flooding, and obfuscated JavaScript.