All Projects → dougludlow → Ng2 Bs3 Modal

dougludlow / Ng2 Bs3 Modal

Licence: isc
Angular Bootstrap 3 Modal Component

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Ng2 Bs3 Modal

Ngautocomplete
Light-weight autocomplete component for Angular.
Stars: ✭ 52 (-80.95%)
Mutual labels:  angular-component, angular2
Ngx Smart Modal
Modal/Dialog component crafted for Angular
Stars: ✭ 256 (-6.23%)
Mutual labels:  modal, angular2
Ng Snotify
Angular 2+ Notification Center
Stars: ✭ 304 (+11.36%)
Mutual labels:  angular-component, angular2
Angular Cropperjs
CropperJS integration for Angular +6
Stars: ✭ 88 (-67.77%)
Mutual labels:  angular-component, angular2
Angular Notifier
A well designed, fully animated, highly customizable, and easy-to-use notification library for your Angular application.
Stars: ✭ 175 (-35.9%)
Mutual labels:  angular-component, angular2
Ng2 Bootstrap Modal
Library to simplify the work with bootstrap modal dialogs
Stars: ✭ 53 (-80.59%)
Mutual labels:  modal, angular2
Ngx Avatar
Universal avatar component for angular 2+ applications makes it possible to fetch / generate avatar from different sources
Stars: ✭ 210 (-23.08%)
Mutual labels:  angular-component, angular2
awesome-angular
💖 A list of awesome Angular (2️⃣➕) resources
Stars: ✭ 61 (-77.66%)
Mutual labels:  angular2, angular-component
angular4-seed-starter
An angular4 starter with webpack2+aot+lazyload+hmr+scss(个人搭的angular4 starter,使用webpack2,包含aot、lazyload、scss、热替换功能等等)
Stars: ✭ 23 (-91.58%)
Mutual labels:  angular2
bootstrap-modal-wrapper
Bootstrap modal factory that supports dynamic modal creations and nested stacked modal features.
Stars: ✭ 18 (-93.41%)
Mutual labels:  modal
D2PCurvedModal
An elegant and curved modal View for iOS (Swift)
Stars: ✭ 59 (-78.39%)
Mutual labels:  modal
react-micro-modal
Accessible, lightweight and configurable modal component with a11y-enabled.
Stars: ✭ 36 (-86.81%)
Mutual labels:  modal
Ngx Slider
Self-contained, mobile friendly slider component for Angular 6+ based on angularjs-slider
Stars: ✭ 258 (-5.49%)
Mutual labels:  angular2
Ngu Carousel
Angular Universal carousel
Stars: ✭ 263 (-3.66%)
Mutual labels:  angular2
ionic-modal-custom-transitions
Add Custom Transitions to Ionic Modals.
Stars: ✭ 22 (-91.94%)
Mutual labels:  angular2
ngx-magicsearch
Magic Search/Faceted Search Library for Angular 2
Stars: ✭ 19 (-93.04%)
Mutual labels:  angular2
Cupertino Pane
🎉📱Multi-functional panes and boards for next generation progressive applications
Stars: ✭ 267 (-2.2%)
Mutual labels:  modal
Ngx Drag To Select
A lightweight, fast, configurable and reactive drag-to-select component for Angular 6 and beyond
Stars: ✭ 262 (-4.03%)
Mutual labels:  angular2
ng-radio
RxJS-based message bus service for Angular2
Stars: ✭ 12 (-95.6%)
Mutual labels:  angular2
next-use-contextual-routing
Generate contextual routing / modal routes paths for Next.js
Stars: ✭ 76 (-72.16%)
Mutual labels:  modal

ng2-bs3-modal npm version npm downloads Build Status

Angular (2+) Bootstrap 3 Modal Component

Demo

http://dougludlow.github.io/ng2-bs3-modal/

Dependencies

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. Example:

npm install jquery [email protected]^3.3.7

./jquery.ts

import * as $ from 'jquery';
window['jQuery'] = window['$'] = $;

./main.ts

import './jquery';
import 'bootstrap/js/modal'; // or just 'bootstrap'
import 'bootstrap/dist/css/bootstrap.css'; // optional

Install

npm

npm install --save ng2-bs3-modal

yarn

yarn add ng2-bs3-modal

Then include the module in the imports collection of your app's module:

import { NgModule } from '@angular/core';
import { BsModalModule } from 'ng2-bs3-modal';

@NgModule({
    imports: [ BsModalModule ]
    ...
})
export class MyAppModule { }

API

BsModalComponent

Inputs

  • 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.

Outputs

  • 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.

Methods

  • 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.

BsModalHeaderComponent

Inputs

  • showDismiss: boolean, default: false

    Show or hide the close button in the header. Specify true to show.

BsModalFooterComponent

Inputs

  • 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.

BsModalService

Methods

  • dismissAll(): void

    Dismiss all open modals. Inject the BsModalService into a componet/service to use.

Example Usage

Default modal

<button type="button" class="btn btn-default" (click)="modal.open()">Open me!</button>

<bs-modal #modal>
    <bs-modal-header [showDismiss]="true">
        <h4 class="modal-title">I'm a modal!</h4>
    </bs-modal-header>
    <bs-modal-body>
        Hello World!
    </bs-modal-body>
    <bs-modal-footer [showDefaultButtons]="true"></bs-modal-footer>
</bs-modal>

Example

Static modal

This will create a modal that cannot be closed with the escape key or by clicking outside of the modal.

<bs-modal #modal [keyboard]="false" [backdrop]="'static'">
    <bs-modal-header [showDismiss]="false">
        <h4 class="modal-title">I'm a modal!</h4>
    </bs-modal-header>
    <bs-modal-body>
        Hello World!
    </bs-modal-body>
    <bs-modal-footer [showDefaultButtons]="true"></bs-modal-footer>
</bs-modal>

Use custom buttons in footer

<bs-modal #modal>
    <bs-modal-header>
        <h4 class="modal-title">I'm a modal!</h4>
    </bs-modal-header>
    <bs-modal-body>
        Hello World!
    </bs-modal-body>
    <bs-modal-footer>
        <button type="button" class="btn btn-default" data-dismiss="modal" (click)="modal.dismiss()">Cancel</button>
        <button type="button" class="btn btn-primary" (click)="modal.close()">Ok</button>
    </bs-modal-footer>
</bs-modal>

Example

Opening and closing the modal from a parent component

import { Component, ViewChild } from '@angular/core';
import { BsModalComponent } from 'ng2-bs3-modal';

@Component({
    selector: 'parent-component',
    template: `
        <bs-modal #myModal>
            ...
        </bs-modal>
    `
})
export class ParentComponent {
    @ViewChild('myModal')
    modal: BsModalComponent;

    close() {
        this.modal.close();
    }
    
    open() {
        this.modal.open();
    }
}

Opening the modal when the parent component loads

import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { BsModalComponent } from 'ng2-bs3-modal';

@Component({
    selector: 'parent-component',
    template: `
        <bs-modal #myModal>
            ...
        </bs-modal>
    `
})
export class ParentComponent implements AfterViewInit {
    @ViewChild('myModal')
    modal: BsModalComponent;

    ngAfterViewInit() {
        this.modal.open();
    }
}

Note: ViewChild doesn't resolve the modal property until AfterViewInit. OnInit is too early and will result in an "undefined" error.

Multiple modals in a component

import { Component, ViewChild } from '@angular/core';
import { BsModalComponent } from 'ng2-bs3-modal';

@Component({
    selector: 'parent-component',
    template: `
        <bs-modal #myFirstModal>
            ...
        </bs-modal>
        <bs-modal #mySecondModal>
            ...
        </bs-modal>
    `
})
export class ParentComponent {
    @ViewChild('myFirstModal')
    modal1: BsModalComponent;
    
    @ViewChild('mySecondModal')
    modal2: BsModalComponent;
    
    ...
}

Modal with a custom size

import { Component, ViewChild } from '@angular/core';
import { BsModalComponent } from 'ng2-bs3-modal';

@Component({
    selector: 'parent-component',
    styles: ['>>> .modal-xl { width: 1100px; }'],
    template: `
        <bs-modal cssClass="modal-xl" #modal>
            ...
        </bs-modal>
    `
})
export class ParentComponent {
    ...
}

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.

Modal in NgFor

import { Component, ViewChildren } from '@angular/core';
import { BsModalComponent } from 'ng2-bs3-modal';

@Component({
    selector: 'parent-component',
    template: `
        <button type="button" class="btn btn-default" (click)="modal.open()">Open me!</button>
        <div *ngFor="let item in items; trackBy: item.id">
            <bs-modal #modal>
                ...
            </bs-modal>
        </div>
    `
})
export class ParentComponent {
    @ViewChildren(BsModalComponent)
    modals: QueryList<BsModalComponent>; // How to access a collection of modals
    ...
}

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.

Modal with validation

<bs-modal #validationModal>
    <form #modalForm="ngForm">
        <bs-modal-header [showDismiss]="true">
            <h4 class="modal-title">I'm a modal!</h4>
        </bs-modal-header>
        <bs-modal-body>
            <div class="form-group">
                <label for="firstName">First Name</label>
                <input type="text" class="form-control" required [(ngModel)]="firstName" name="firstName" id="firstName">
            </div>
            <div class="form-group">
                <label for="lastName">Last Name</label>
                <input type="text" class="form-control" required [(ngModel)]="lastName" name="lastName" id="lastName">
            </div>
        </bs-modal-body>
        <bs-modal-footer>
            <button type="button" class="btn btn-default" data-dismiss="modal" (click)="validationModal.dismiss()">Cancel</button>
            <button type="button" class="btn btn-primary" [disabled]="!modalForm.valid" (click)="validationModal.close()">Save</button>
        </bs-modal-footer>
    </form>
</bs-modal>

Autofocus on a textbox when modal is opened

<bs-modal #modal>
    <bs-modal-header>
        <h4 class="modal-title">I'm a modal!</h4>
    </bs-modal-header>
    <bs-modal-body>
        <div class="form-group">
            <label for="textbox">I'm a textbox!</label>
            <input autofocus type="text" class="form-control" id="textbox">
        </div>        
    </bs-modal-body>
    <bs-modal-footer [showDefaultButtons]="true"></bs-modal-footer>
</bs-modal>

Building

git clone https://github.com/dougludlow/ng2-bs3-modal.git
yarn
yarn build

Running

yarn start

Navigate to http://localhost:4200/ in your browser.

Testing

yarn test:lib

Bugs/Contributions

Report all bugs and feature requests on the issue tracker.

Contributions are welcome! Feel free to open a pull request.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].