Inspired by [angular-toastr] (https://github.com/Foxandxss/angular-toastr) for AngularJS 2.x
npm install angular2-toastr``js`
map: {
//...
'angular2-toastr': 'npm:angular2-toastr'
}
-and in packages:
`js`
packages: {
//...
'angular2-toastr': {
main: './index.js',
defaultExtension: 'js'
}
- Import style into your index.html. Choose one of the following files:
- style-default.css - Contains DEFAULT themestyle-bootstrap.css
- - Contains Bootstrap 3 themestyle-material.css
- - Contains Material Design theme
OR
- Copy and Paste :
- Copy and paste these files in your application.
- Link them in your index.html
`ts`
- Select the Theme [default, bootstrap, material].
- Select the Position [top-left, top-right, top-center, bottom-left, bottom-right, bottom-center]
- Assign them as shown below:
`ts`
`ts
import {BrowserModule} from "@angular/platform-browser";
import {NgModule} from '@angular/core';
import {ToasterComponent, ToastComponent, ToasterAppComponent} from 'angular2-toastr/index';
@NgModule({
imports: [ BrowserModule ],
declarations: [ToasterComponent, ToastComponent, ToasterAppComponent]
bootstrap: [AppComponent]
})
export class AppModule {
}
`
from angular2-toaster in your application code:`ts
import {Component} from '@angular/core';
import {ToasterService} from 'angular2-toaster/index';@Component({
selector: 'app',
providers: [ToasterService],
template:
})
export class AppComponent {
constructor(private _toaster: ToasterService) {
}
addToast() {
// See all possible types in one shot.
// pass parameters as (title:string, message:string, show_close_button:boolean, timeout:number)
this._toaster.success('title', 'message', true, 1000);
this._toaster.error('title', 'message', true, 2000);
this._toaster.info('title', 'message', true, 3000);
this._toaster.warning('title', 'message', true, 4000);
this._toaster.wait('title', 'message', true, 0);
}
}
`
OR
- Add Service Globally in NgModule :
`ts
import {BrowserModule} from "@angular/platform-browser";
import {NgModule} from '@angular/core';
import {ToasterComponent, ToastComponent, ToasterAppComponent, ToasterService} from 'angular2-toastr/index';@NgModule({
imports: [ BrowserModule ],
declarations: [ToasterComponent, ToastComponent, ToasterAppComponent],
providers: [ToasterService],
bootstrap: [AppComponent]
})
export class AppModule {
}
``