Gathering detailed insights and metrics for ng2-bs3-modal
Gathering detailed insights and metrics for ng2-bs3-modal
Gathering detailed insights and metrics for ng2-bs3-modal
Gathering detailed insights and metrics for ng2-bs3-modal
npm install ng2-bs3-modal
Typescript
Module System
TypeScript (75.6%)
HTML (18.68%)
JavaScript (5.52%)
CSS (0.2%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
ISC License
259 Stars
227 Commits
133 Forks
24 Watchers
11 Branches
12 Contributors
Updated on Mar 06, 2025
Latest Version
0.15.0
Package Id
ng2-bs3-modal@0.15.0
Unpacked Size
490.48 kB
Size
118.05 kB
File Count
68
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
5
Angular (2+) Bootstrap 3 Modal Component
http://dougludlow.github.io/ng2-bs3-modal/demo/
If you're using Typescript in your project, ng2-bs3-modal
requires Typescript v2.0.0 or greater. Also make sure that your editor (Visual Studio Code, Atom, Webstorm, etc.) supports Typescript >= v2.0.0 or you'll see errors even though it compiles.
ng2-bs3-modal
depends on bootstrap
which depends on jquery
, you'll need to include both scripts before ng2-bs3-modal
or somehow make them available globally, depending on your build system.
1<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js"></script> 2<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
npm
1npm install --save ng2-bs3-modal
yarn
1yarn add ng2-bs3-modal
Then include the ng2-bs3-modal
in your project.
Using SystemJS, you can add a mapping to your System.config
:
1System.config({ 2 defaultJSExtensions: true, 3 map: { 4 'ng2-bs3-modal': 'node_modules/ng2-bs3-modal' 5 } 6});
Or you can include a reference to the bundle in your html:
1<script src="node_modules/ng2-bs3-modal/bundles/ng2-bs3-modal.system.js"></script>
Then include the module in the imports
collection of your app's module:
1import { NgModule } from '@angular/core'; 2import { BsModalModule } from 'ng2-bs3-modal'; 3 4@NgModule({ 5 imports: [ BsModalModule ] 6 ... 7}) 8export class MyAppModule { }
The following is a list of basic demo projects that use the ng2-bs3-modal
:
Feel free to request more.
animation: boolean
, default: true
Specify false
to simply show the modal rather than having it fade in/out of view.
backdrop: string | boolean
, default: true
Specify 'static'
for a backdrop which doesn't close the modal on click or false
for no backdrop.
keyboard: boolean
, default: true
Closes the modal when escape key is pressed. Specify false
to disable.
size: string
, default: undefined
Specify 'sm'
for small and 'lg'
for large.
cssClass: string
, default: undefined
Applies the given class to the modal. Can be used to styles the modal; for example, giving it a custom size.
onShow: EventEmitter<Event>
Emits when the show.bs.modal
event is triggered, just before the modal is shown. Call Event.preventDefault()
to cancel the modal from showing.
onHide: EventEmitter<BsModalHideEvent>
Emits when the hide.bs.modal
event is triggered, just before the modal is hidden. Call BsModalHideEvent.event.preventDefault()
to cancel the modal from hiding.
onClose: EventEmitter<any>
Emits when ModalComponent.close()
is called. Will emit whatever was passed into ModalComponent.close()
.
onDismiss: EventEmitter<BsModalHideType>
Emits when ModalComponent.dismiss()
is called, or when the modal is dismissed with the keyboard or backdrop. Returns a BsModalHideType
that can be used to determine how the modal was dismissed.
onOpen: EventEmitter
Emits when ModalComponent.open()
is called.
open(size?: string): Promise
Opens the modal. Size is optional. Specify 'sm'
for small and 'lg'
for large to override size. Returns a promise that resolves when the modal is completely shown.
close(value?: any): Promise<any>
Closes the modal. Causes onClose
to be emitted. Returns a promise that resolves the value passed to close
when the modal is completely hidden.
dismiss(): Promise
Dismisses the modal. Causes onDismiss
to be emitted. Returns a promise that resolves when the modal is completely hidden.
showDismiss: boolean
, default: false
Show or hide the close button in the header. Specify true
to show.
showDefaultButtons: boolean
, default: false
Show or hide the default 'Close' and 'Dismiss' buttons in the footer. Specify true
to show.
closeButtonLabel: string
, default: 'Close'
Change the label in the default 'Close' button in the footer. Has no effect if showDefaultButtons aren't set.
dismissButtonLabel: string
, default: 'Dismiss'
Change the label in the default 'Dismiss' button in the footer. Has no effect if showDefaultButtons aren't set.
dismissAll(): void
Dismiss all open modals. Inject the BsModalService
into a componet/service to use.
1<button type="button" class="btn btn-default" (click)="modal.open()">Open me!</button> 2 3<bs-modal #modal> 4 <bs-modal-header [showDismiss]="true"> 5 <h4 class="modal-title">I'm a modal!</h4> 6 </bs-modal-header> 7 <bs-modal-body> 8 Hello World! 9 </bs-modal-body> 10 <bs-modal-footer [showDefaultButtons]="true"></bs-modal-footer> 11</bs-modal>
This will create a modal that cannot be closed with the escape key or by clicking outside of the modal.
1<bs-modal #modal [keyboard]="false" [backdrop]="'static'"> 2 <bs-modal-header [showDismiss]="false"> 3 <h4 class="modal-title">I'm a modal!</h4> 4 </bs-modal-header> 5 <bs-modal-body> 6 Hello World! 7 </bs-modal-body> 8 <bs-modal-footer [showDefaultButtons]="true"></bs-modal-footer> 9</bs-modal>
1<bs-modal #modal> 2 <bs-modal-header> 3 <h4 class="modal-title">I'm a modal!</h4> 4 </bs-modal-header> 5 <bs-modal-body> 6 Hello World! 7 </bs-modal-body> 8 <bs-modal-footer> 9 <button type="button" class="btn btn-default" data-dismiss="modal" (click)="modal.dismiss()">Cancel</button> 10 <button type="button" class="btn btn-primary" (click)="modal.close()">Ok</button> 11 </bs-modal-footer> 12</bs-modal>
1import { Component, ViewChild } from '@angular/core'; 2import { BsModalComponent } from 'ng2-bs3-modal'; 3 4@Component({ 5 selector: 'parent-component', 6 template: ` 7 <bs-modal #myModal> 8 ... 9 </bs-modal> 10 ` 11}) 12export class ParentComponent { 13 @ViewChild('myModal') 14 modal: BsModalComponent; 15 16 close() { 17 this.modal.close(); 18 } 19 20 open() { 21 this.modal.open(); 22 } 23}
1import { Component, ViewChild, AfterViewInit } from '@angular/core'; 2import { BsModalComponent } from 'ng2-bs3-modal'; 3 4@Component({ 5 selector: 'parent-component', 6 template: ` 7 <bs-modal #myModal> 8 ... 9 </bs-modal> 10 ` 11}) 12export class ParentComponent implements AfterViewInit { 13 @ViewChild('myModal') 14 modal: BsModalComponent; 15 16 ngAfterViewInit() { 17 this.modal.open(); 18 } 19}
Note: ViewChild
doesn't resolve the modal
property until AfterViewInit
. OnInit
is too early and will result in an "undefined" error.
1import { Component, ViewChild } from '@angular/core'; 2import { BsModalComponent } from 'ng2-bs3-modal'; 3 4@Component({ 5 selector: 'parent-component', 6 template: ` 7 <bs-modal #myFirstModal> 8 ... 9 </bs-modal> 10 <bs-modal #mySecondModal> 11 ... 12 </bs-modal> 13 ` 14}) 15export class ParentComponent { 16 @ViewChild('myFirstModal') 17 modal1: BsModalComponent; 18 19 @ViewChild('mySecondModal') 20 modal2: BsModalComponent; 21 22 ... 23}
1import { Component, ViewChild } from '@angular/core'; 2import { BsModalComponent } from 'ng2-bs3-modal'; 3 4@Component({ 5 selector: 'parent-component', 6 styles: ['>>> .modal-xl { width: 1100px; }'], 7 template: ` 8 <bs-modal cssClass="modal-xl" #modal> 9 ... 10 </bs-modal> 11 ` 12}) 13export class ParentComponent { 14 ... 15}
Note: Angular2 emulates the shadow dom by prefixing component styles with a unique identifier. Because the modal is attached to the body tag, it doesn't pick up these styles. You will need to add the /deep/
or >>>
selector in order for the style to take effect. See Component Styles.
1import { Component, ViewChildren } from '@angular/core'; 2import { BsModalComponent } from 'ng2-bs3-modal'; 3 4@Component({ 5 selector: 'parent-component', 6 template: ` 7 <button type="button" class="btn btn-default" (click)="modal.open()">Open me!</button> 8 <div *ngFor="let item in items; trackBy: item.id"> 9 <bs-modal #modal> 10 ... 11 </bs-modal> 12 </div> 13 ` 14}) 15export class ParentComponent { 16 @ViewChildren(BsModalComponent) 17 modals: QueryList<BsModalComponent>; // How to access a collection of modals 18 ... 19}
Note: If you are updating items asynchronously, make sure you are using trackBy
in the ngFor
directive so that Angular doesn't teardown and redraw the elements each time the collection is changed. See NgFor Directive for more details.
1<bs-modal #validationModal> 2 <form #modalForm="ngForm"> 3 <bs-modal-header [showDismiss]="true"> 4 <h4 class="modal-title">I'm a modal!</h4> 5 </bs-modal-header> 6 <bs-modal-body> 7 <div class="form-group"> 8 <label for="firstName">First Name</label> 9 <input type="text" class="form-control" required [(ngModel)]="firstName" name="firstName" id="firstName"> 10 </div> 11 <div class="form-group"> 12 <label for="lastName">Last Name</label> 13 <input type="text" class="form-control" required [(ngModel)]="lastName" name="lastName" id="lastName"> 14 </div> 15 </bs-modal-body> 16 <bs-modal-footer> 17 <button type="button" class="btn btn-default" data-dismiss="modal" (click)="validationModal.dismiss()">Cancel</button> 18 <button type="button" class="btn btn-primary" [disabled]="!modalForm.valid" (click)="validationModal.close()">Save</button> 19 </bs-modal-footer> 20 </form> 21</bs-modal>
1<bs-modal #modal> 2 <bs-modal-header> 3 <h4 class="modal-title">I'm a modal!</h4> 4 </bs-modal-header> 5 <bs-modal-body> 6 <div class="form-group"> 7 <label for="textbox">I'm a textbox!</label> 8 <input autofocus type="text" class="form-control" id="textbox"> 9 </div> 10 </bs-modal-body> 11 <bs-modal-footer [showDefaultButtons]="true"></bs-modal-footer> 12</bs-modal>
1git clone https://github.com/dougludlow/ng2-bs3-modal.git 2yarn 3yarn build
1yarn start
Navigate to http://localhost:4200/ in your browser.
1yarn test
To run tests once without watching:
1yarn test:single
Report all bugs and feature requests on the issue tracker.
Contributions are welcome! Feel free to open a pull request.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/30 approved changesets -- score normalized to 1
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
188 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More