Angular Bootstrap Modal
Modal dialog for angular 6 applications using bootstrap 4. If used without bootstrap, please add appropriate styles for modal to work properly. Raise an issue on github if found any. Please star the project if you found it useful.
npm install --save ngb-modal
For Angular[2,4,5] and bootstrap 3, install older version
npm install --save firstname.lastname@example.org
For Angular 6 and bootstrap 3, install older version
npm install --save email@example.com
Check working Demo. You can test and generate code snippet from demo.
ModalModule into your module
Now Start using modal component in your components.
Modal header content goes there.Modal body content goes there.Modal footer content goes there.
* title?: String;* size?: String | "md";* modalClass?: String | '';* hideCloseButton?: Boolean | false;* centered?: Boolean | false;* backdrop?: Boolean | 'static' | true;* animation?: Boolean | true;* keyboard?: Boolean | true;* closeOnOutsideClick?: Boolean | true;* backdropClass?: String | "modal-backdrop";
Note: These properties can be passed in html on modal tag or pass as an 2nd parameter in
open method of
ModalManager when opening a modal as shown below.
Opening a Modal
Separate component as modal:
You can make a separate component for modal window. In this case remember to add your component as an
entryComponents section of your
ViewContainerRef in your root component as below.
Note: If you are using another component as modal. Don't forget to add
@ViewChild(ModalComponent) ModalComponent in your component as above.
ModalComponent property to be present on your component class. Don't change the name.
Any input property of your component can be passed to modalInstance returned by
ModalManager expose 4 methods to component to control the modal.
* open: Method // used open a particular modal. 1st argument is modalRefence you want to open,2nd is config you want to be applied on this modal.It returns instance of opened modal, which has 3 properties:* onOpen : Observable // fired once this modal is opened* onClose : Observable // fired once this modal is closed* close : Method // can be used to close this modal* close : Method //Used to close any opened modal by passing the reference of that modal.* setDefaults : Method //to be called from root component to provide global configurations for all modals.* setRootViewContainerRef: Method //called if using separate component as modal. called from root component to set container for all modals at root level.
These 2 output events are published on
onOpen : Fired after modal is opened.
onClose : Fired after modal is closed
If you want to set some default properties for all modals used in project, these configurations can be set via
setDefaults method of
setDefaults from your root component and the configurations.
MIT © Uttam Pratap Choudhary