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 :: vue prop string or number 
Javascript :: javascript get array min and max 
Javascript :: get all cookies 
Javascript :: basic server on node.js 
Javascript :: html form post json example 
Javascript :: firestore add document 
Javascript :: how to pause js execution 
Javascript :: is node js faster than python 
Javascript :: regex phone number 
Javascript :: check url with javascript 
Javascript :: how to change the text using jquery on click 
Javascript :: flatlist horizontal 
Javascript :: javascript array reorder elements 
Javascript :: how to instance in a node with code godot 
Javascript :: falsy value javascript 
Javascript :: regex for email validation 
Javascript :: javascript reset form 
Javascript :: react js onclick call two functions 
Javascript :: .split is not a function 
Javascript :: toggle hook react 
Javascript :: javascript get class name 
Javascript :: react transition group 
Javascript :: how to know if a number has a decimal number js 
Javascript :: get date in javascript 
Javascript :: hex string to buffer nodejs 
Javascript :: import a script to my react componetn 
Javascript :: joi custom error 
Javascript :: jquery add event after page load 
Javascript :: javascript download current html page 
Javascript :: javascript loop and array 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =