GithubHelp home page GithubHelp logo

dougludlow / ng2-bs3-modal Goto Github PK

View Code? Open in Web Editor NEW
262.0 26.0 133.0 1.07 MB

Angular Bootstrap 3 Modal Component

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

License: ISC License

HTML 18.68% TypeScript 75.60% JavaScript 5.52% CSS 0.20%
angular angular2 modal ng2-bs3-modal angular-component

ng2-bs3-modal's Introduction

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 bootstrap@^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.

ng2-bs3-modal's People

Contributors

assaulter avatar dougludlow avatar ishehata avatar jamiewastin avatar jcannata avatar kevinbulme avatar lmcarreiro avatar loetscher avatar npmcdn-to-unpkg-bot avatar samvloeberghs avatar vicabelotelova avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ng2-bs3-modal's Issues

Install fails

When running npm install ng2-bs3-modal I get the following error.
Is there anything I'm doing wrong?

npm ERR! Darwin 15.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "ng2-bs3-modal"
npm ERR! node v5.6.0
npm ERR! npm  v3.7.2
npm ERR! code ELIFECYCLE

npm ERR! [email protected] postinstall: `npm run peer`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script 'npm run peer'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ng2-bs3-modal package,
npm ERR! not with npm itself.

npm-debug.log.zip

Add id value into modal-dialog.

I'm using your package to show modal-dialog. I want to custom width of modal-dialog. Currently we only can set width by add size value(sm or lg). Can you add id value (defined in "modal" selector) into the root div like this:
<div class="modal-dialog" [ngClass]="{ 'modal-sm': isSmall(), 'modal-lg': isLarge() }" id="your-custom-id">`
I think with id value we can custom style for modal-dialog easily.
Please help me to solve this issue. Thanks.

How create a public modal?

Hi,
I am using your ng2-bs3-modal with my project. And has once trouble as I want to create a public modal component, like this user login component. then anywhere other in component can be import the user login component usage.

user-login.component.ts

import {Component} from 'angular2/core';
import { MODAL_DIRECTIVES } from 'ng2-bs3-modal/ng2-bs3-modal';

@Component({
    selector: 'user-login-modal',
    directives: [MODAL_DIRECTIVES],
    template: `
<modal #modal>
    <modal-header [show-close]="true">
        <h4 class="modal-title">I'm a modal!</h4>
    </modal-header>
    <modal-body>
        Hello World!
    </modal-body>
    <modal-footer [show-default-buttons]="true"></modal-footer>
</modal>
    `
})

export class UserLoginModalComponent {
    open(){
        this.modal.open();
    }

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

}

a.component.ts

import {UserLoginModalComponent} from 'user-login.component';
import {Component} from 'angular2/core';

@Component({
    selector: 'my-modal',
    directives: [MODAL_DIRECTIVES],
    template: `
<h1>this is parents component</h1>
<button (click)="modal.open()">Login Modal</button>
<user-login-modal></user-login-modal>
    `
})

export class AComponent {}

b.component.ts

import {UserLoginModalComponent} from 'user-login.component';
import {Component} from 'angular2/core';

@Component({
    selector: 'my-modal',
    directives: [MODAL_DIRECTIVES],
    template: `
<h1>this is parents component</h1>
<button (click)="modal.open()">Login Modal</button>
<user-login-modal></user-login-modal>
    `
})

export class BComponent {}

Tell me any way idea, Thanks!

Is it would be possible to open a modal located in a « son » component from the parent one?

To be clear, I have:

<dashboard>
  <dashboard-products>> parent component
    <button type="button" class="DashboardProducts-header-menu-addCode (click)="openCreationModal() »>> should call #productModal
    <modal-product>> another of my components in which I call your component
        … —> my code
        <modal #productModal></modal>
    </modal-product>
  </dashboard-products>
</dashboard>

If I include directly the modal component inside the parent of course it works, but is it possible to do it that way?

Out of date deps?

├── UNMET PEER DEPENDENCY @angular/common@^2.0.0-rc.1
├── UNMET PEER DEPENDENCY @angular/compiler@^2.0.0-rc.1
├── UNMET PEER DEPENDENCY @angular/core@^2.0.0-rc.1
├── UNMET PEER DEPENDENCY @angular/platform-browser@^2.0.0-rc.1
├── UNMET PEER DEPENDENCY @angular/platform-browser-dynamic@^2.0.0-rc.1
└── [email protected]

I am running the latest angular2 packages.

Multiple modal from parent component?

From the docs, I custom it a bit to support multiple from parent component, but seem like it doesn't work. It always call the last ViewChild modal.
I guess this problem happen because we only have one instance of ModalComponent.
Is it possible to make something like:
modal.init(#modal-id)

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

@Component({
    selector: 'parent-component',
    directives: [MODAL_DIRECTIVES],
    template: `
        <modal #myModal>
            ...
        </modal>
        <modal #my2ndModal>
            ...
        </modal>
    `
})
export class ParentComponent {
    @ViewChild('myModal')
    @ViewChild('my2ndModal')
    modal: ModalComponent;

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

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

onClose emit undefined

    close(): Promise<void> {
        return this.instance.close().then(() => {
            this.onClose.emit(undefined);
        });
    }

why onClose emit undefined? how to get the ModalResult?

angular2-2.0.0-beta.11 close dialog more than once gives error.

When opening and closing a modal more than once, throws an error of "Error: Task does not support cancellation, or is already canceled." Not sure if this is an angular2 issue or an issue here. It was working on an earlier version before the upgrade.

Support Angular 2.0.0-rc.1

Dear Doug!

Can you please upgrade your module to support Angular 2.0.0-rc.1?

Current problem - now Angular is on a different path:
node_modules/ng2-bs3-modal/ng2-bs3-modal.d.ts(1,22): error TS2307: Cannot find module 'angular2/core'.

More info here:
https://github.com/angular/angular/blob/master/CHANGELOG.md

And if you have any ngFor loops at your module, you shoud change the # to let. Tha was a breaking change in beta.17.

Thank you for your help!

How do you open the modal from an Angular2 EventEmitter callback?

Having trouble determining how i would open a modal not from a click event? I see the example to close one, but i am not sure where the @ViewChild lives. Can you shed some insight on this please

My angular component click event calls a method to pass in an Id, i need too look up the details of the id on the server then show the modal...

Thanks

fsevents

It looks like you depend on a package "[email protected]". Unfortunately this only is supported on MacOsX. Is this an important dependency? I'd like to try an use your project on Windows.

escape key

Apparently if you leave the tabindex="-1" off the div, the escape key wont close the modal automatically.

Any chance you could add an input for the modal to not close on escape which sets that tabindex?

Thanks!

Love the modal otherwise!

How can I close the modal from within the modal body?

I've got some radio buttons inside the modal body and I want to close the modal
when the radio button is selected..... inside the (click)=

I've tried close(), modal.close(), parent.close(), parent.modal.close()

Resize issue if using a custom component in modal-body

Hello,

I'm creating on my page a modal, and in the body of it I put a custom component mail-template-form

        <modal (onClose)="closed()" #modal>
            <modal-header [show-close]="true">
                <h4 class="modal-title">Envoyer le devis</h4>
            </modal-header>
            <modal-body>
                <mail-template-form showSubmit="false" [mailTemplate]="mailTemplate" #mtf></mail-template-form>
            </modal-body>
            <modal-footer>
                <button (click)="modal.dismiss()" class="btn btn-default">Fermer</button>
                <button (click)="modal.close()" class="btn btn-success">Envoyer</button>
            </modal-footer>
        </modal>

When rendered, the modal-body's div height is 0, which causes a bad display of the modal footer's buttons.
captura de pantalla 2016-04-07 a las 09 10 46

TypeError: this.$modal.modal is not a function

I keep getting

TypeError: this.$modal.modal is not a function

when I click a button to open a modal with this.modal.open().

I've tried to find the error but can't figure it out.
When I am inspecting this.$modal.modal(); in modal-instance.js:37 it looks like this.

0:modal.modal.fade
context:modal.modal.fade
length:1

Which feels wrong but I dunno. :P

My dependencies are:

    "@angular/common": "2.0.0-rc.1",
    "@angular/compiler": "2.0.0-rc.1",
    "@angular/core": "2.0.0-rc.1",
    "@angular/http": "2.0.0-rc.1",
    "@angular/platform-browser": "2.0.0-rc.1",
    "@angular/platform-browser-dynamic": "2.0.0-rc.1",
    "@angular/router": "2.0.0-rc.1",
    "@angular/router-deprecated": "^2.0.0-rc.1",
    "bootstrap-sass": "^3.3.6",
    "core-js": "^2.3.0",
    "es6-shim": "^0.35.0",
    "jquery": "^2.2.3",
    "ng2-bootstrap": "^1.0.13",
    "ng2-bs3-modal": "^0.6.1",
    "reflect-metadata": "^0.1.3",
    "rxjs": "^5.0.0-beta.6",
    "systemjs": "0.19.25",
    "zone.js": "^0.6.12"

Would appreciate any help (Y)

Unable to install "npm install --save ng2-bs3-modal"

while trying to installing i am getting this error
32028 error Windows_NT 6.1.7601 32029 error argv "C:\\Program Files (x86)\\nodejs\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--save" "ng2-bs3-modal" 32030 error node v4.4.0 32031 error npm v2.14.20 32032 error code EBADPLATFORM 32033 error notsup Unsupported 32033 error notsup Not compatible with your operating system or architecture: [email protected] 32033 error notsup Valid OS: darwin 32033 error notsup Valid Arch: any 32033 error notsup Actual OS: win32 32033 error notsup Actual Arch: ia32 32034 verbose exit [ 1, true ] 32035 verbose unbuild node_modules\ng2-bs3-modal 32036 info preuninstall [email protected] 32037 info uninstall [email protected] 32038 verbose unbuild rmStuff [email protected] from E:\wsJs\h5\popups\node_modules 32039 info postuninstall [email protected]


While using -f install works. But run time exception is there.

this.$modal.modal is not a function

Hi, by opening modal I am getting:

TypeError: this.$modal.modal is not a function
    at ModalInstance.show (modal-instance.ts:49)

what could it be?

License?

Hey, there! Could you please add a license to this repo? :) Thanks!

Input parameters orther than a boolean is ignored

In modal-footer.ts, I added
@Input('action-button-text') actionButtonText: string= "Save";

Within the template, I added
<button type="button" class="btn btn-info" (click)="modal.close()" [hidden]="!showDefaultButtons">{{actionButtonText}}</button>

And Finally, within the modal itself, i added
<modal-footer [action-button-text]="Delete" [show-default-buttons]="true"></modal-footer>

This just shows a blank button, instead of a button with the text "Delete". Changing the input parameter to a boolean works Or actually passing in a boolean value from the modal template. Any ideas :) ?

Attempt to use a dehydrated detector: ... -> onClose

I'm stumped on an issue where if ComponentA (route: ./componentA) opens up a modal, and the component routes you to ComponentB (route: ./componentB), I get a crash with the following log:

angular2.js?1458337616513:23597 EXCEPTION: Attempt to use a dehydrated detector: NavbarComponent_0 -> onClose

Alongside with the exception, the app is properly routed to ComponentB, but it has the black transparent background stuck on the screen and I'm unable to get past it.

It's a bit urgent that I fix this and any workaround is welcome, thanks!

Full stack trace:

angular2.js?1458337616513:23597 Error: Attempt to use a dehydrated detector: NavbarComponent_0 -> onClose
at DehydratedException.BaseException as constructor
at new DehydratedException (http://localhost:5555/node_modules/angular2/bundles/angular2.js?1458337616513:4928:14)
at AbstractChangeDetector.throwDehydratedError (http://localhost:5555/node_modules/angular2/bundles/angular2.js?1458337616513:8274:13)
at AbstractChangeDetector.handleEvent (http://localhost:5555/node_modules/angular2/bundles/angular2.js?1458337616513:8110:14)
at AbstractChangeDetector.eval (viewFactory_NavbarComponent:493:106)
at http://localhost:5555/node_modules/angular2/bundles/angular2.js?1458337616513:13188:36
at cb (http://localhost:5555/node_modules/angular2/bundles/angular2.js?1458337616513:13592:15)
at http://localhost:5555/node_modules/angular2/bundles/angular2-polyfills.js?1458337616512:1679:44
at Zone.run (http://localhost:5555/node_modules/angular2/bundles/angular2-polyfills.js?1458337616512:1243:24)
at Zone.run (http://localhost:5555/node_modules/angular2/bundles/angular2.js?1458337616513:13543:32)

-----async gap-----
Error
at _getStacktraceWithUncaughtError (http://localhost:5555/node_modules/angular2/bundles/angular2-polyfills.js?1458337616512:2244:29)
at Zone.fork (http://localhost:5555/node_modules/angular2/bundles/angular2-polyfills.js?1458337616512:2293:47)
at arguments.(anonymous function) (http://localhost:5555/node_modules/angular2/bundles/angular2-polyfills.js?1458337616512:1671:82)

-----async gap-----
Error
at _getStacktraceWithUncaughtError (http://localhost:5555/node_modules/angular2/bundles/angular2-polyfills.js?1458337616512:2244:29)
at Zone.fork (http://localhost:5555/node_modules/angular2/bundles/angular2-polyfills.js?1458337616512:2293:47)
at Zone.bind (http://localhost:5555/node_modules/angular2/bundles/angular2-polyfills.js?1458337616512:1218:53)
at bindArguments (http://localhost:5555/node_modules/angular2/bundles/angular2-polyfills.js?1458337616512:1401:36)
at lib$es6$promise$promise$$Promise.obj.(anonymous function) as then
at NavbarComponent.onLogoutUserClicked (http://localhost:5555/app/components/shared/navbar.component.js:44:35)
at AbstractChangeDetector.ChangeDetector_NavbarComponent_0.handleEventInternal (viewFactory_NavbarComponent:468:38)
at AbstractChangeDetector.handleEvent (http://localhost:5555/node_modules/angular2/bundles/angular2.js?1458337616513:8115:25)
at AppView.triggerEventHandlers (http://localhost:5555/node_modules/angular2/bundles/angular2.js?1458337616513:10815:34)
at eval (viewFactory_NavbarComponent:1094:120)

-----async gap-----
Error
at _getStacktraceWithUncaughtError (http://localhost:5555/node_modules/angular2/bundles/angular2-polyfills.js?1458337616512:2244:29)
at Zone.fork (http://localhost:5555/node_modules/angular2/bundles/angular2-polyfills.js?1458337616512:2293:47)
at NgZone.createInnerZone (http://localhost:5555/node_modules/angular2/bundles/angular2.js?1458337616513:13531:39)
at new NgZone (http://localhost:5555/node_modules/angular2/bundles/angular2.js?1458337616513:13397:32)
at createNgZone (http://localhost:5555/node_modules/angular2/bundles/angular2.js?1458337616513:12460:12)
at PlatformRef
.application (http://localhost:5555/node_modules/angular2/bundles/angular2.js?1458337616513:12535:31)
at Object.bootstrap (http://localhost:5555/node_modules/angular2/bundles/angular2.js?1458337616513:25335:64)
at Object.eval (http://localhost:5555/main.js:9:11)
at eval (http://localhost:5555/main.js:17:4)
at SystemJSLoader.__exec (http://localhost:5555/node_modules/systemjs/dist/system.src.js?1458337616511:1400:16)

bug: need to ignore destruction if $model does not exist

please fix in:

ngOnDestroy() {
        if (!this.$modal)
            return;
        this.$modal.data('bs.modal', null);
        this.$modal.remove();
    }

since in some cases, if you never actaully open a modal, yet the ModalComponent gets instantiated by the View, the $modal will not exist on the destroy, so please add if (!this.$modal) return;

tx

Sean

Successful integration with angular-cli project

Apologies in advance. This is not an issue, wasn't sure where to put this, but might be helpful for some:

Step 1: Install
npm install --save ng2-bs3-modal

Step 2: Include in Vendor files
Open ember-cli-build.js
include 'ng2-bs3-modal' in vendorNpmFiles array:

var Angular2App = require('angular-cli/lib/broccoli/angular2-app');

module.exports = function(defaults) {
  var app = new Angular2App(defaults, {
    vendorNpmFiles: [
      'angularfire2/**/*.js',
      'firebase/lib/*.js',
      'ng2-bs3-modal/**/*.js'
    ]
  });
  return app.toTree();
};

Step 3: Build
ng build
Check /dist/vendor for ng2-bs3-modal folder

Step 4: Include Scripts and CSS in index.html
Open index.html
In the head include:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css">

In the body (with the other script src tags) include:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>

Step 5: System.js
In index.html, in System.config({}) add 'ng2-bs3-modal' to packages and map.

Example:

System.config({
      packages: {
        app: {
          format: 'register',
          defaultExtension: 'js'
        },
        'ng2-material': {
            format: 'cjs',
            defaultExtension: 'js'
        },
        angularfire2: {
            defaultExtension: 'js',
            main: 'angularfire2.js'
        },
        'ng2-bs3-modal': {
            defaultExtension: 'js',
            main: 'ng2-bs3-modal.js'
        }
      },
      map: {
        firebase: 'vendor/firebase/lib/firebase-web.js',
        angularfire2: 'vendor/angularfire2',
        'ng2-bs3-modal': 'vendor/ng2-bs3-modal'
      }
    });
System.import('app.js').then(null, console.error.bind(console));

Step 6: Import in component ts file and include in directives array

import { MODAL_DIRECTIVES} from 'ng2-bs3-modal/ng2-bs3-modal';

directives: [ROUTER_DIRECTIVES, CORE_DIRECTIVES, MATERIAL_DIRECTIVES, MODAL_DIRECTIVES],

Should now be able to use ng2-bs3-modal with you angular-cli project.

404 ng2-bs3-modal/ng2-bs3-modal not found

I'm using Angular 2 beta 8 based on the angular2-quickstart module.
ng2-bs3-modal is installed in node_modules and I'm using the import given in the documentation

import {MODAL_DIRECTIVES} from 'ng2-bs3-modal/ng2-bs3-modal';

The Typescript compiler can find the module however it results in a 404 with the browser trying to access http://devapp/ng2-bs3-modal/ng2-bs3-modal

Similar import directive lines such as

import {ROUTER_DIRECTIVES} from 'angular2/router';

work fine. Am I missing something in System.config?

error on build in windows 10

c:\msweb\ng2-bs3-modal>npm run build

> [email protected] build c:\msweb\ng2-bs3-modal
> npm run clean && npm run lint && npm run tsc && npm run bundles


> [email protected] clean c:\msweb\ng2-bs3-modal
> node ./node_modules/.bin/rimraf ./bundles/ ./components/ ./ng2-bs3-modal.js ./ng2-bs3-modal.d.ts

c:\msweb\ng2-bs3-modal\node_modules\.bin\rimraf:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)

Do not close modal if form is invalid

I have a requirement where the modal should have an input form with text fields and also validations. If the validations fail it should not close the pop up when the user presses ‘Save’ on the modal. Is there a way to block the close event and also how can I have validations messages on the form itself.

Undefined when using modal.open()/modal.close() in parent component

Hi, I am working on a production application, and throughout the project had problems using for instance "this.modal.open() " in the component.ts file.

Console gives
browser_adapter.ts:78 ORIGINAL EXCEPTION: TypeError: Cannot read property 'open' of undefined.

The strange thing is that in one of the components, which has several instances of the modal component, one of them works. The other modals will give the error explained above. So only one of the modal-objects in one component file is working.

For some of the modals-objects, it is fine just to use the method inside the html-file. This works perfectly.
But now we have come to a point where we need one of the modals to be triggered in the parent.ts component.

We are using the modal in several components as well where it is only one modal-instace in the html file, but we will get the same error. Followed your examples correclty and tried to copy it to see if we have done something wrong, but it just will give the same error.

All imports are included and directives are used correctly. Triple checked several times, and I have got to the conclusion that it is time to make an issue, as I just cannot figure out what is wrong or if this is a common issue?

Thanks

npm module is depended on SystemJs

The direct use of the npm module as explained is depending on SystemJS.
As I'm using Webpack this seems like unexpected behaviour and somewhat unfortunate design.

Can you please share your feedback on this @dougludlow ?
I'd be happy to use this, but for now I need to reference the src folder directly.

Grtz!

TypeError: require is not a function

rror: TypeError: require is not a function
        at eval (http://localhost:3000/node_modules/ng2-bs3-modal/ng2-bs3-modal.js:5:15)
        at eval (http://localhost:3000/node_modules/ng2-bs3-modal/ng2-bs3-modal.js:23:3)
        at ZoneDelegate.invoke (http://localhost:3000/node_modules/angular2/bundles/angular2-polyfills.js:332:29)
    Evaluating http://localhost:3000/node_modules/ng2-bs3-modal/ng2-bs3-modal.js
    Error loading http://localhost:3000/node_modules/ng2-bs3-modal/ng2-bs3-modal.js as "ng2-bs3-modal/ng2-bs3-modal" from http://localhost:3000/app/main-menu.component.js

when putting the MODAL_DIRECTIVES

error when including in my package.json

Hello,

Im using VS2015, and wanted to add it from npm, so adding "ng2-bs3-modal": "0.4.2" to my package.json gave the folowing error:

npm WARN peerDependencies The peer dependency [email protected] included from ng2-bs3-modal will no npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly. npm WARN peerDependencies The peer dependency [email protected] included from ng2-bs3-modal will no npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly. npm ERR! Windows_NT 6.3.9600 npm ERR! argv "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" npm ERR! node v0.12.2 npm ERR! npm v2.7.4 npm ERR! code EBADPLATFORM npm ERR! notsup Unsupported npm ERR! notsup Not compatible with your operating system or architecture: [email protected] npm ERR! notsup Valid OS: darwin npm ERR! notsup Valid Arch: any npm ERR! notsup Actual OS: win32 npm ERR! notsup Actual Arch: ia32 npm ERR! Please include the following file with any support request: npm ERR! C:\Users\andre\Documents\Visual Studio 2015\Projects\Angular2Testing\Angular2Testing\src\Shoppius\npm-debug.log

I have no idea what can i do.

I can install any other packages without problem. Including angular, bootstrap and others.

Thanks!

Could you be more specific on example?

I've been trying to integrating this with an Angular 2 based web app, but keep getting errors on modal not found error.

Please provide a new example, this is very important stuff you are working on, make it usable to the community.

Thanks!

Modals in ngFor

Hey!

Im getting problems when I'm running this in an *ngFor.

"EXCEPTION: Error in /app/components/application/resource-panel/resource-panel.html:52:62
↵ORIGINAL EXCEPTION: TypeError: self._ModalComponent_62_4 is not a function
↵ORIGINAL STACKTRACE:↵TypeError: self._ModalComponent_62_4 is not a function
↵    at DebugAppView._View_ResourcePanelComponent0._handle_submit_72_0 (ResourcePanelComponent.template.js:812:20)
↵    at eval (eval at <anonymous> (http://localhost:8081/bundle.js:1:0), <anonymous>:316:24)
↵    at eval (eval at <anonymous> (http://localhost:8081/bundle.js:1:0), <anonymous>:278:36)
↵    at eval (eval at <anonymous> (http://localhost:8081/bundle.js:1:0), <anonymous>:20:93)
↵    at ZoneDelegate.invoke (eval at <anonymous> (http://localhost:8081/bundle.js:1:0), <anonymous>:323:29)
↵    at Object.NgZoneImpl.inner.inner.fork.onInvoke (eval at <anonymous> (http://localhost:8081/bundle.js:1:0), <anonymous>:45:41)
↵    at ZoneDelegate.invoke (eval at <anonymous> (http://localhost:8081/bundle.js:1:0), <anonymous>:322:35)
↵    at Zone.runGuarded (eval at <anonymous> (http://localhost:8081/bundle.js:1:0), <anonymous>:230:48)
↵    at NgZoneImpl.runInnerGuarded (eval at <anonymous> (http://localhost:8081/bundle.js:1:0), <anonymous>:78:78)
↵    at NgZone.runGuarded (eval at <anonymous> (http://localhost:8081/bundle.js:1:0), <anonymous>:228:73)
↵ERROR CONTEXT:↵[object Object]"

Any suggestions?

Getting error on modal.open(): this.$modal.appendTo(...).modal is not a function

I took the example given on the code tab, and an getting an error

ng2-bs3-modal.ts:19 EXCEPTION: Error during evaluation of "click"
ng2-bs3-modal.ts:19 EXCEPTION: Error during evaluation of "click"BrowserDomAdapter.logError @ ng2-bs3-modal.ts:19BrowserDomAdapter.logGroup @ ng2-bs3-modal.ts:19ExceptionHandler.call @ ng2-bs3-modal.ts:19(anonymous function) @ ng2-bs3-modal.ts:19schedulerFn @ ng2-bs3-modal.ts:19SafeSubscriber.__tryOrUnsub @ ng2-bs3-modal.ts:19SafeSubscriber.next @ ng2-bs3-modal.ts:19Subscriber._next @ ng2-bs3-modal.ts:19Subscriber.next @ ng2-bs3-modal.ts:19Subject._finalNext @ ng2-bs3-modal.ts:19Subject._next @ ng2-bs3-modal.ts:19Subject.next @ ng2-bs3-modal.ts:19EventEmitter.emit @ ng2-bs3-modal.ts:19NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ ng2-bs3-modal.ts:19NgZoneImpl.inner.inner.fork.onHandleError @ ng2-bs3-modal.ts:19ZoneDelegate.handleError @ angular2-polyfills.js:326Zone.runGuarded @ angular2-polyfills.js:235NgZoneImpl.runInner @ ng2-bs3-modal.ts:19NgZone.run @ ng2-bs3-modal.ts:19outsideHandler @ ng2-bs3-modal.ts:19ZoneDelegate.invokeTask @ angular2-polyfills.js:355Zone.runTask @ angular2-polyfills.js:254ZoneTask.invoke @ angular2-polyfills.js:422
ng2-bs3-modal.ts:19 ORIGINAL EXCEPTION: TypeError: this.$modal.appendTo(...).modal is not a functionBrowserDomAdapter.logError @ ng2-bs3-modal.ts:19ExceptionHandler.call @ ng2-bs3-modal.ts:19(anonymous function) @ ng2-bs3-modal.ts:19schedulerFn @ ng2-bs3-modal.ts:19SafeSubscriber.__tryOrUnsub @ ng2-bs3-modal.ts:19SafeSubscriber.next @ ng2-bs3-modal.ts:19Subscriber._next @ ng2-bs3-modal.ts:19Subscriber.next @ ng2-bs3-modal.ts:19Subject._finalNext @ ng2-bs3-modal.ts:19Subject._next @ ng2-bs3-modal.ts:19Subject.next @ ng2-bs3-modal.ts:19EventEmitter.emit @ ng2-bs3-modal.ts:19NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ ng2-bs3-modal.ts:19NgZoneImpl.inner.inner.fork.onHandleError @ ng2-bs3-modal.ts:19ZoneDelegate.handleError @ angular2-polyfills.js:326Zone.runGuarded @ angular2-polyfills.js:235NgZoneImpl.runInner @ ng2-bs3-modal.ts:19NgZone.run @ ng2-bs3-modal.ts:19outsideHandler @ ng2-bs3-modal.ts:19ZoneDelegate.invokeTask @ angular2-polyfills.js:355Zone.runTask @ angular2-polyfills.js:254ZoneTask.invoke @ angular2-polyfills.js:422
ng2-bs3-modal.ts:19 ORIGINAL STACKTRACE:BrowserDomAdapter.logError @ ng2-bs3-modal.ts:19ExceptionHandler.call @ ng2-bs3-modal.ts:19(anonymous function) @ ng2-bs3-modal.ts:19schedulerFn @ ng2-bs3-modal.ts:19SafeSubscriber.__tryOrUnsub @ ng2-bs3-modal.ts:19SafeSubscriber.next @ ng2-bs3-modal.ts:19Subscriber._next @ ng2-bs3-modal.ts:19Subscriber.next @ ng2-bs3-modal.ts:19Subject._finalNext @ ng2-bs3-modal.ts:19Subject._next @ ng2-bs3-modal.ts:19Subject.next @ ng2-bs3-modal.ts:19EventEmitter.emit @ ng2-bs3-modal.ts:19NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ ng2-bs3-modal.ts:19NgZoneImpl.inner.inner.fork.onHandleError @ ng2-bs3-modal.ts:19ZoneDelegate.handleError @ angular2-polyfills.js:326Zone.runGuarded @ angular2-polyfills.js:235NgZoneImpl.runInner @ ng2-bs3-modal.ts:19NgZone.run @ ng2-bs3-modal.ts:19outsideHandler @ ng2-bs3-modal.ts:19ZoneDelegate.invokeTask @ angular2-polyfills.js:355Zone.runTask @ angular2-polyfills.js:254ZoneTask.invoke @ angular2-polyfills.js:422
ng2-bs3-modal.ts:19 TypeError: this.$modal.appendTo(...).modal is not a function
    at ModalInstance.create (ng2-bs3-modal.ts:19)
    at ModalInstance.open (ng2-bs3-modal.ts:19)
    at ModalComponent.open (ng2-bs3-modal.ts:19)
    at AbstractChangeDetector.ChangeDetector_PolicyListComponent_1.handleEventInternal (viewFactory_PolicyListComponent:264)
    at AbstractChangeDetector.handleEvent (ng2-bs3-modal.ts:19)
    at AppView.triggerEventHandlers (ng2-bs3-modal.ts:19)
    at eval (viewFactory_PolicyListComponent:547)
    at ng2-bs3-modal.ts:19
    at ng2-bs3-modal.ts:19
    at ZoneDelegate.invoke (angular2-polyfills.js:322)

Current Versions:

 "angular2": "^2.0.0-beta.11",
    "bootstrap": "^3.3.6",
    "es6-promise": "^3.1.2",
    "es6-shim": "^0.35.0",
    "font-awesome": "^4.5.0",
    "jquery": "^2.1.4",
    "ng2-bs3-modal": "^0.4.2",
    "reflect-metadata": "0.1.3",
    "rxjs": "^5.0.0-beta.3",
    "systemjs": "^0.19.24",
    "toastr": "^2.1.2",
    "zone.js": "^0.6.5"

Code is as follows

Component:

import { MODAL_DIRECTIVES } from 'ng2-bs3-modal/ng2-bs3-modal';

@Component({
    selector: 'one-policylist',
    templateUrl: 'views/policylist.view.html',
    directives: [PolicyCardComponent, ContentLoadingComponent, MODAL_DIRECTIVES]
})

View:

<ul *ngIf="policies.length > 0" class="policy-list-container">
    <li><button type="button" class="btn btn-default" (click)="modal.open()">Open me!</button></li>
</ul>
<div *ngIf="policies.length == 0">
    <one-contentloading [message]="'Retrieving policies...'"></one-contentloading> 
</div>
<modal #modal>
    <modal-header [show-close]="true">
        <h4 class="modal-title">I'm a modal!</h4>
    </modal-header>
    <modal-body>
        Hello World!
    </modal-body>
    <modal-footer [show-default-buttons]="true"></modal-footer>
</modal>

Any help would be great

Documentation tweak

In your example, you document your backdrop attribute as

[backdrop]="'static'"

If you would like, and for you information, can actually specify it through normal attribute assignment

backdrop='static'

Feel free to do it either way, just wanted to let you know =)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.