All Projects → akserg → Ng2 Toasty

akserg / Ng2 Toasty

Licence: mit
Angular2 Toasty component shows growl-style alerts and messages for your app.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Ng2 Toasty

Ngx Scroll To
Scroll to any element to enhance scroll-based features in you app. Works for Angular 4+, both AoT and SSR. No dependencies.
Stars: ✭ 269 (-7.56%)
Mutual labels:  angular2, angular4
ngmodule-viz
Visualize the dependencies between the NgModules in your Angular 2+ application
Stars: ✭ 35 (-87.97%)
Mutual labels:  angular2, angular4
angular2-cookie-law
Angular2+ component that provides a banner to inform users about cookie law
Stars: ✭ 38 (-86.94%)
Mutual labels:  angular2, angular4
angular2-crud-auth-routing
Sample Angular (2.x, 4.x) project with Contacts CRUD + routing + simple authentication
Stars: ✭ 60 (-79.38%)
Mutual labels:  angular2, angular4
angular4-seed-starter
An angular4 starter with webpack2+aot+lazyload+hmr+scss(个人搭的angular4 starter,使用webpack2,包含aot、lazyload、scss、热替换功能等等)
Stars: ✭ 23 (-92.1%)
Mutual labels:  angular2, angular4
angular-material-datatransfer
A HTML5 datatransfer UI for handling upload and download of multiple simultaneous files.
Stars: ✭ 13 (-95.53%)
Mutual labels:  angular2, angular4
angular-progress-bar
This component allow you to easy incorporate progress-bar to angular/ionic project, providing binding and color options
Stars: ✭ 26 (-91.07%)
Mutual labels:  angular2, angular4
angular-rollbar-source-maps
Angular 2+ implementation to upload sourcemaps to Rollbar
Stars: ✭ 17 (-94.16%)
Mutual labels:  angular2, angular4
ionic-modal-custom-transitions
Add Custom Transitions to Ionic Modals.
Stars: ✭ 22 (-92.44%)
Mutual labels:  angular2, angular4
Angular-Firebase-Sortable-Table
Angular Firebase Sortable Table is a module that makes tables creation with firebase an easy task.
Stars: ✭ 28 (-90.38%)
Mutual labels:  angular2, angular4
angular-particle
Particle.js rewritted for Angular2/4
Stars: ✭ 58 (-80.07%)
Mutual labels:  angular2, angular4
Angular-Movies
Angular Movies | TV Shows is a simple web app that consumes The Movie DB API - Angular 13 + Material Angular
Stars: ✭ 35 (-87.97%)
Mutual labels:  angular2, angular4
angular-adal-quickstart
Quickstart/Seed for using Microsoft's AAD Authentication with Angular (2/4).
Stars: ✭ 22 (-92.44%)
Mutual labels:  angular2, angular4
ncg-crud-ngx-md
Angular 4+ Material Design CRUD/Admin app by NinjaCodeGen http://DNAfor.NET
Stars: ✭ 36 (-87.63%)
Mutual labels:  angular2, angular4
angular-ninja
The way to be an Angular ninja
Stars: ✭ 44 (-84.88%)
Mutual labels:  angular2, angular4
ng2-timezone-selector
A simple Angular module to create a timezone selector using moment-timezone.
Stars: ✭ 12 (-95.88%)
Mutual labels:  angular2, angular4
ionic-uuchat
基于ionic3,angular4的实时聊天app,兼容web端。该项目只是前端部分,所有数据需要请求后端服务器,需要配套express-uuchat-api使用。
Stars: ✭ 14 (-95.19%)
Mutual labels:  angular2, angular4
ng4-stompjs-demo
A sample using Angular4, Angular CLI and @stom/ng2-stompjs
Stars: ✭ 20 (-93.13%)
Mutual labels:  angular2, angular4
ngx-redux-ui-management-recipes
Recipes for managing the UI layout of an application using Redux in Angular
Stars: ✭ 39 (-86.6%)
Mutual labels:  angular2, angular4
ngx-smart-loader
Smart loader handler to manage loaders everywhere in Angular apps.
Stars: ✭ 28 (-90.38%)
Mutual labels:  angular2, angular4

Angular 2 Toasty npm version npm monthly downloads

Angular2 Toasty component shows growl-style alerts and messages for your application.

Build Status semantic-release Commitizen friendly Dependency Status devDependency Status Known Vulnerabilities

Follow me twitter to be notified about new releases.

Some of these APIs and Components are not final and are subject to change!

Installation

npm install ng2-toasty --save

Demo

Simple examples using ng2-dnd:

Online demo available here

Plunker demo available here

Usage

If you use SystemJS to load your files, you might have to update your config:

System.config({
    map: {
        'ng2-toasty': 'node_modules/ng2-toasty/bundles/index.umd.js'
    }
});

1. Update the markup

  • Import style into your web page. Choose one of the following files;
    • style-default.css - Contains DEFAULT theme
    • style-bootstrap.css - Contains Bootstrap 3 theme
    • style-material.css - Contains Material Design theme
  • Assign the selected theme name [default, bootstrap, material] to the theme property of the instance of ToastyConfig.
  • Add <ng2-toasty></ng2-toasty> tag in template of your application component.

2. Import the ToastyModule

Import ToastyModule.forRoot() in the NgModule of your application. The forRoot method is a convention for modules that provide a singleton service.

import {BrowserModule} from "@angular/platform-browser";
import {NgModule} from '@angular/core';
import {ToastyModule} from 'ng2-toasty';

@NgModule({
    imports: [
        BrowserModule,
        ToastyModule.forRoot()
    ],
    bootstrap: [AppComponent]
})
export class AppModule {
}

If you have multiple NgModules and you use one as a shared NgModule (that you import in all of your other NgModules), don't forget that you can use it to export the ToastyModule that you imported in order to avoid having to import it multiple times.

@NgModule({
    imports: [
        BrowserModule,
        ToastyModule.forRoot()
    ],
    exports: [BrowserModule, ToastyModule],
})
export class SharedModule {
}

3. Use the ToastyService for your application

  • Import ToastyService from ng2-toasty in your application code:
import {Component} from '@angular/core';
import {ToastyService, ToastyConfig, ToastOptions, ToastData} from 'ng2-toasty';

@Component({
    selector: 'app',
    template: `
        <div>Hello world</div>
        <button (click)="addToast()">Add Toast</button>
        <ng2-toasty></ng2-toasty>
    `
})
export class AppComponent {
    
    constructor(private toastyService:ToastyService, private toastyConfig: ToastyConfig) { 
        // Assign the selected theme name to the `theme` property of the instance of ToastyConfig. 
        // Possible values: default, bootstrap, material
        this.toastyConfig.theme = 'material';
    }
    
    addToast() {
        // Just add default Toast with title only
        this.toastyService.default('Hi there');
        // Or create the instance of ToastOptions
        var toastOptions:ToastOptions = {
            title: "My title",
            msg: "The message",
            showClose: true,
            timeout: 5000,
            theme: 'default',
            onAdd: (toast:ToastData) => {
                console.log('Toast ' + toast.id + ' has been added!');
            },
            onRemove: function(toast:ToastData) {
                console.log('Toast ' + toast.id + ' has been removed!');
            }
        };
        // Add see all possible types in one shot
        this.toastyService.info(toastOptions);
        this.toastyService.success(toastOptions);
        this.toastyService.wait(toastOptions);
        this.toastyService.error(toastOptions);
        this.toastyService.warning(toastOptions);
    }
}

4. How dynamically update title and message of a toast

Here is an example of how to dynamically update message and title of individual toast:

import {Component} from '@angular/core';
import {ToastyService, ToastyConfig, ToastyComponent, ToastOptions, ToastData} from 'ng2-toasty';
import {Subject, Observable, Subscription} from 'rxjs/Rx';

@Component({
    selector: 'app',
    template: `
        <div>Hello world</div>
        <button (click)="addToast()">Add Toast</button>
        <ng2-toasty></ng2-toasty>
    `
})
export class AppComponent {
    
    getTitle(num: number): string {
        return 'Countdown: ' + num;
    }

    getMessage(num: number): string {
        return 'Seconds left: ' + num;
    }
    
    constructor(private toastyService:ToastyService) { }
    
    addToast() {
        let interval = 1000;
        let timeout = 5000;
        let seconds = timeout / 1000;
        let subscription: Subscription;
        
        let toastOptions: ToastOptions = {
            title: this.getTitle(seconds),
            msg: this.getMessage(seconds),
            showClose: true,
            timeout: timeout,
            onAdd: (toast: ToastData) => {
                console.log('Toast ' + toast.id + ' has been added!');
                // Run the timer with 1 second iterval
                let observable = Observable.interval(interval).take(seconds);
                // Start listen seconds beat
                subscription = observable.subscribe((count: number) => {
                    // Update title of toast
                    toast.title = this.getTitle(seconds - count - 1);
                    // Update message of toast
                    toast.msg = this.getMessage(seconds - count - 1);
                });

            },
            onRemove: function(toast: ToastData) {
                console.log('Toast ' + toast.id + ' has been removed!');
                // Stop listenning
                subscription.unsubscribe();
            }
        };

        switch (this.options.type) {
            case 'default': this.toastyService.default(toastOptions); break;
            case 'info': this.toastyService.info(toastOptions); break;
            case 'success': this.toastyService.success(toastOptions); break;
            case 'wait': this.toastyService.wait(toastOptions); break;
            case 'error': this.toastyService.error(toastOptions); break;
            case 'warning': this.toastyService.warning(toastOptions); break;
        }
    }
}

5. How to close specific toast

Here is an example of how to close an individual toast:

import {Component} from '@angular/core';
import {ToastyService, ToastyConfig, ToastyComponent, ToastOptions, ToastData} from 'ng2-toasty';
import {Subject, Observable, Subscription} from 'rxjs/Rx';

@Component({
    selector: 'app',
    template: `
        <div>Hello world</div>
        <button (click)="addToast()">Add Toast</button>
        <ng2-toasty></ng2-toasty>
    `
})
export class AppComponent {
    
    getTitle(num: number): string {
        return 'Countdown: ' + num;
    }

    getMessage(num: number): string {
        return 'Seconds left: ' + num;
    }
    
    constructor(private toastyService:ToastyService) { }
    
    addToast() {
        let interval = 1000;
        let subscription: Subscription;
        
        let toastOptions: ToastOptions = {
            title: this.getTitle(0),
            msg: this.getMessage(0),
            showClose: true,
            onAdd: (toast: ToastData) => {
                console.log('Toast ' + toast.id + ' has been added!');
                // Run the timer with 1 second iterval
                let observable = Observable.interval(interval);
                // Start listen seconds beat
                subscription = observable.subscribe((count: number) => {
                    // Update title of toast
                    toast.title = this.getTitle(count);
                    // Update message of toast
                    toast.msg = this.getMessage(count);
                    // Extra condition to hide Toast after 10 sec
                    if (count > 10) {
                        // We use toast id to identify and hide it
                        this.toastyService.clear(toast.id);
                    }
                });

            },
            onRemove: function(toast: ToastData) {
                console.log('Toast ' + toast.id + ' has been removed!');
                // Stop listenning
                subscription.unsubscribe();
            }
        };

        switch (this.options.type) {
            case 'default': this.toastyService.default(toastOptions); break;
            case 'info': this.toastyService.info(toastOptions); break;
            case 'success': this.toastyService.success(toastOptions); break;
            case 'wait': this.toastyService.wait(toastOptions); break;
            case 'error': this.toastyService.error(toastOptions); break;
            case 'warning': this.toastyService.warning(toastOptions); break;
        }
    }
}

6. Customize the ng2-toasty for your application in template

You can use the following properties to customize the ng2-toasty component in your template:

  • position - The window position where the toast pops up. Default value is bottom-right. Possible values: bottom-right, bottom-left, top-right, top-left, top-center, bottom-center, center-center Example:
<ng2-toasty [position]="'top-center'"></ng2-toasty>

Credits

Inspired by angular-toasty

License

[MIT](/LICENSE

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