Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to add toaster in angular 9

npm install ngx-toastr --save
Comment

add toaster in angular

npm install ngx-toastr --save
//or
npm install ngx-toastr@13.2.1 --save

npm install @angular/animations --save

//angular.json
"styles": [
              "src/styles.css",
              "node_modules/ngx-toastr/toastr.css"              
            ],
//-----------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 { }

//-----------------------------------------------------------
//app.Component.html 
<h1>Angular 12 Toastr Notifications Example</h1><br>
   
<button (click)="showToasterSuccess()" class="btn btn-success">
    Success Toaster
</button>&nbsp;
   
<button (click)="showToasterError()" class="btn btn-danger">
    Error Toaster
</button>&nbsp;
   
<button (click)="showToasterInfo()" class="btn btn-info">
    Info Toaster
</button>&nbsp;
   
<button (click)="showToasterWarning()" class="btn btn-warning">
    Warning Toaster
</button>&nbsp;


//---------------app.Component.ts----------------------
import { Component } from '@angular/core';
import { ToastrService } from 'ngx-toastr'
   
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'toaster-not';
   
  constructor(private toastr: ToastrService) { }
   
  showToasterSuccess(){
    this.toastr.success("Data shown successfully !!", "Data shown successfully !!")
  }
   
  showToasterError(){
    this.toastr.error("Something is wrong", "Something is wrong")
  }
   
  showToasterInfo(){
    this.toastr.info("This is info", "This is info")
  }
   
  showToasterWarning(){
    this.toastr.warning("This is warning", "This is warning")
  }
}
Comment

install toastr in angular

npm install ngx-toastr --save
Comment

PREVIOUS NEXT
Code Example
Javascript :: toaster for angular 
Javascript :: JavaScript function that generates all combinations of a string. 
Javascript :: object inside object javascript 
Javascript :: center element in react native 
Javascript :: how to use jquery timepicker 
Javascript :: mongodb sort query 
Javascript :: javascript early break reduce() method 
Javascript :: reversed array loop 
Javascript :: expo build ios 
Javascript :: class element in javascript 
Javascript :: expo open app settings 
Javascript :: replace space with hyphen/dash javascript 
Javascript :: conditionally changing styled components based on props 
Javascript :: regexp object javascript 
Javascript :: 150 pound in kg 
Javascript :: javascript make async get request 
Javascript :: how to get key from a button in react 
Javascript :: how to merge two sorted arrays in javascript 
Javascript :: how to change text color in react 
Javascript :: Change the HTML of an element 
Javascript :: ajax request in javascript 
Javascript :: javascript remove style 
Javascript :: how to remove duplicates in array in javascript 
Javascript :: sort javascript number array with duplicates 
Javascript :: clear all intervals js 
Javascript :: how to get url params value in node js 
Javascript :: how to get which key is pressed in javascript 
Javascript :: javascript canvas grayscale 
Javascript :: process env react undefined 
Javascript :: discord js clear message from id 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =