Angular 2 Toasty
Angular2 Toasty component shows growl-style alerts and messages for your application.
Follow me 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:
- with SystemJS in ng2-systemjs-demo
- with Webpack in ng2-webpack-demo
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;
1. Update the markup
- Import style into your web page. Choose one of the following files;
style-default.css
- Contains DEFAULT themestyle-bootstrap.css
- Contains Bootstrap 3 themestyle-material.css
- Contains Material Design theme
- Assign the selected theme name [
default
,bootstrap
,material
] to thetheme
property of the instance of ToastyConfig. - Add
<ng2-toasty></ng2-toasty>
tag in template of your application component.
ToastyModule
2. Import the Import ToastyModule.forRoot()
in the NgModule of your application.
The forRoot
method is a convention for modules that provide a singleton service.
;;;
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.
ToastyService
for your application
3. Use the - Import
ToastyService
fromng2-toasty
in your application code:
;; @ { // Assign the selected theme name to the `theme` property of the instance of ToastyConfig. // Possible values: default, bootstrap, material thistoastyConfigtheme = 'material'; } { // Just add default Toast with title only thistoastyService; // Or create the instance of ToastOptions var toastOptions:ToastOptions = title: "My title" msg: "The message" showClose: true timeout: 5000 theme: 'default' { console; } { console; } ; // Add see all possible types in one shot thistoastyService; thistoastyService; thistoastyService; thistoastyService; thistoastyService; }
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:
;;; @ : string return 'Countdown: ' + num; : string return 'Seconds left: ' + num; { } { let interval = 1000; let timeout = 5000; let seconds = timeout / 1000; let subscription: Subscription; let toastOptions: ToastOptions = title: this msg: this showClose: true timeout: timeout { console; // Run the timer with 1 second iterval let observable = Observable; // Start listen seconds beat subscription = observable; } { console; // Stop listenning subscription; } ; }
5. How to close specific toast
Here is an example of how to close an individual toast:
;;; @ : string return 'Countdown: ' + num; : string return 'Seconds left: ' + num; { } { let interval = 1000; let subscription: Subscription; let toastOptions: ToastOptions = title: this msg: this showClose: true { console; // Run the timer with 1 second iterval let observable = Observable; // Start listen seconds beat subscription = observable; } { console; // Stop listenning subscription; } ; }
ng2-toasty
for your application in template
6. Customize the 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 isbottom-right
. Possible values:bottom-right
,bottom-left
,top-right
,top-left
,top-center
,bottom-center
,center-center
Example:
Credits
Inspired by angular-toasty
License
[MIT](/LICENSE