Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
ngx-modal-dialog-custom
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-custom
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.IModalHeaderDialog
.import {Component} from '@angular/core';
import {IModalHeaderDialog} from 'ngx-modal-dialog';
@Component({
selector: 'app-custom-header-modal',
template: `
<h4>This component is a custom header</h4>
<p>Written By: <b>{{title}}</b></p>
`
})
export class CustomHeaderModalComponent implements IModalHeaderDialog {
title: string;
setData(data: any) {
this.title = data['title'];
}
}
ModalDialogService
where you want to open the dialog passing the headerComponent as a new option parameter instead of the title attribute and change the value of the new parameter headerType to CUSTOM:constructor(modalService: ModalDialogService, viewRef: ViewContainerRef) { }
openCustomHeaderModal() {
this.modalDialogService.openDialog(this.viewContainer, {
headerComponent: CustomHeaderModalComponent,
childComponent: SimpleModalComponent,
settings: {
closeButtonClass: 'close theme-icon-close',
headerType: ModalDialogHeaderType.CUSTOM
},
data: {
title: 'Yahima Duarte <layahi@gmail.com>',
text: `Lorem ipsum is placeholder text commonly used in the graphic, print,
and publishing industries for previewing layouts and visual mockups.`
}
});
}
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;
headerComponent: IModalHeaderDialog;
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
headerComponent: any
Component type that will be rendered as a header of modal dialog. Component must implement IModalHeaderDialog
interface.
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;
}
string
string
btn btn-primary
Promise<any> | Observable<any> | boolean
truthful
.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:
true
Action button will initiate alert behavior if return is:
false
If 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;
headerType: ModalDialogHeaderType;
}
string
modal-backdrop fade show
string
show
string
modal fade ngx-modal
string
show
string
modal-dialog modal-dialog-centered
string
modal-content
string
modal-header
string
modal-title
string
close glyphicon glyphicon-remove
string
CLOSE
string
modal-body
string
modal-footer
string
ngx-modal-shake
number
250
string
btn btn-primary
number
true
ModalDialogHeaderType
TITLE
Licensed under MIT
FAQs
Dynamic modal dialog for Angular
The npm package ngx-modal-dialog-custom receives a total of 10 weekly downloads. As such, ngx-modal-dialog-custom popularity was classified as not popular.
We found that ngx-modal-dialog-custom demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.