npm i ngx-toastr
app.module.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { AppComponent } from './app.component'; import { HelloComponent } from './hello.component'; import {ToastrModule} from 'ngx-toastr' @NgModule({ imports: [ BrowserModule, FormsModule ,ToastrModule.forRoot(),BrowserAnimationsModule], declarations: [ AppComponent, HelloComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } |
app.component.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import { Component } from '@angular/core'; import {ToastrService} from 'ngx-toastr' @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent { name = 'Angular 5'; constructor(public toastr: ToastrService){} showSuccess(){ this.toastr.success('everything is broken', 'Major Error', { timeOut: 3000, }); } showError(){ this.toastr.error('everything is broken', 'Major Error', { timeOut: 3000, }); } showInfo(){ this.toastr.info('everything is broken', 'Major Error', { timeOut: 3000, }); } showWarning(){ this.toastr.warning('everything is broken', 'Major Error', { timeOut: 3000, }); } } |
app.component.html
1 2 3 4 5 6 7 8 9 |
<hello name="{{ name }}"></hello> <p> Start editing to see some magic happen :) </p> <button (click)="showSuccess()">Success</button> <button (click)="showError()">Error</button> <button (click)="showInfo()">Info</button> <button (click)="showWarning()">Warning</button> |
FULL SOURCE CODE