Today, We want to share with you Adding Toastr Notifications in Angular 9 Tutorial.In this post we will show you Angular 9 Toastr Notifications Example, hear for angular 6 toast notification we will give you demo and example for implement.In this post, we will learn about Implement Toastr Notification In Angular 7|8|9 with an example.
Adding Toastr Notifications in Angular 9 Tutorial
There are the Following The simple About How to Create Angular Toastr Notifications Full Information With Example and source code.
As I will cover this Post with live Working example to develop ngx-toastr angular 8, so the ngx-toastr angular 7 is used for this example is following below.
Phase 1: Make New App
angular 9 app using bellow command:
ng new my-new-shop
Phase 2: Install Toastr
install ngx-toastr and @angular/animations npm packages
npm install ngx-toastr --save npm install @angular/animations --save
angular.json
..... "styles": [ "node_modules/ngx-toastr/toastr.css", "src/styles.css" ], .....
Phase 3: Import Module
src/app/app.module.ts
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { ToastrModule } from 'ngx-toastr'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule, ToastrModule.forRoot() ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
Phase 4: Make Service for Notification
run bellow command:
ng generate service notification
src/app/notification.service.ts
import { Injectable } from '@angular/core'; import { ToastrService } from 'ngx-toastr'; @Injectable({ providedIn: 'root' }) export class NotificationService { constructor(private toastr: ToastrService) { } displaySuccess(message, title){ this.toastr.success(message, title) } displayError(message, title){ this.toastr.error(message, title) } displayInfo(message, title){ this.toastr.info(message, title) } displayWarning(message, title){ this.toastr.warning(message, title) } }
Phase 5: Updated View File
src/app/app.component.html
<h1>Angular 9 Toastr Notifications Example - Pakainfo.com</h1> <button (click)="displayToasterSuccess()"> Success Toaster </button> <button (click)="displayToasterError()"> Error Toaster </button> <button (click)="displayToasterInfo()"> Info Toaster </button> <button (click)="displayToasterWarning()"> Warning Toaster </button>
Phase 6: Use Component ts File
src/app/app.component.ts
import { Component } from '@angular/core'; import { NotificationService } from './notification.service' @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'toaster-not'; constructor(private notifyService : NotificationService) { } displayToasterSuccess(){ this.notifyService.displaySuccess("Data displayn successfully !!", "Pakainfo.com") } displayToasterError(){ this.notifyService.displayError("Your Data is wrong", "Pakainfo.com") } displayToasterInfo(){ this.notifyService.displayInfo("Your Data is info", "Pakainfo.com") } displayToasterWarning(){ this.notifyService.displayWarning("Your Data is warning", "Pakainfo.com") } }
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about How to Create Angular Toastr Notifications?.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.