Adding Toastr Notifications in Angular 9 Tutorial

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.

Read Also:  Laravel Ajax Autocomplete Search Example

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 :

Read Also:  PHP nested FOR loop multiple conditions - ArrayIterator

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  PHP sleep delay Function increasing execution time
  2. Read Also:  Redirect from one website url to another url
  3. Read Also:  Laravel 5.6 Server Side Validation Example
  4. Read Also:  vue.js Get Current DateTime Example
  5. Read Also:  How to check Laravel version and configuration
  6. Read Also:  Bootstrap Datetimepicker Disable Dates Dynamically
  7. Read Also:  Angular 6 Toast Message Notifications From Scratch
  8. Read Also:  Laravel 6 Custom Middleware Tutorial With Example
  9. Read Also:  PHP and MySqli CRUD Operation Tutorial
  10. Read Also:  Laravel Ajax Autocomplete Search Example
CLOSEX