This package has been deprecated

Author message:

WARNING: This project has been renamed to ng-confirmations. Install using @jaspero/ng-confirmations instead.

@jaspero/ng2-confirmations
TypeScript icon, indicating that this package has built-in type declarations

0.3.3 • Public • Published

Build Status NPM Version

NG2 Confirmations

An easy to use alert library for Angular 2.

npm install --save @jaspero/ng2-confirmations

A demo can be found here

Setup

Import JasperoConfirmationsModule in your @NgModule:

@NgModule({
    imports: [
        JasperoConfirmationsModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule {}

Then create the component in a root component (you can create it anywhere but you can only use it in that component on any lower ones).

<jaspero-confirmations [defaultSettings]="options"></jaspero-confirmations>

How To Use

You need to import the ConfirmationService in your component:

constructor(private _confirmation: ConfirmationService) {}

Then use the create(title: string, message: string, settings: ConfirmSettings) method to initiate thr confirmation modal.

open() {
    this._confirmation.create('Do something?', 'You should really just do it.')
        // The confirmation returns an Observable Subject which will notify you about the outcome
        .subscribe((ans: ResolveEmit) => console.log(ans))
}

ResolveEmit

This is returned by the create() method.

export interface ResolveEmit {
    // Returns this if modal resolved with yes or no
    resolved?: boolean;
    // If the modal was closed in some other way this is removed
    closedWithOutResolving?: string;
}

If the modal was closed by clicking on yes/no this is returned:

{resolved: true // false if no was pressed}

If the modal was closed in any other way:

{closedWithOutResolving: 'overlayClick' // reason for closing}

Options

Available settings:

export interface ConfirmSettings {
    overlay?: boolean; // Default: true
    overlayClickToClose?: boolean; // Default: true
    showCloseButton?: boolean; // Default: true
    confirmText?: string; // Default: 'Yes'
    declineText?: string; // Default: 'No'
}

You can provide the settings as input to the <jaspero-confirmations></jaspero-confirmations> component. Making the settings default for each created alert. However you can also override the settings by passing them in the create() method.

FAQ

Does this library support AoT?

Yes AoT is supported.

Does the defaultSettings input need to be provided?

No, if none was provided the defaults are used.

Package Sidebar

Install

npm i @jaspero/ng2-confirmations

Weekly Downloads

19

Version

0.3.3

License

MIT

Last publish

Collaborators

  • flauc1