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 :: how to read 2 dimensional array in javascript 
Javascript :: consoleLine 
Javascript :: count word and space in text javascript 
Javascript :: serving html file using node.js 
Javascript :: express how to refresh 
Javascript :: passing state in link react 
Javascript :: reduce break 
Javascript :: nextjs check production or development environment 
Javascript :: array vowels 
Javascript :: get url react 
Javascript :: list all functions in an object js 
Javascript :: get dir from filepath javascript 
Javascript :: convert number to boolean javascript 
Javascript :: pi in js 
Javascript :: jquery cdn in react 
Javascript :: settimeout vs requestanimationframe 
Javascript :: add react to existing project 
Javascript :: multiple click events in react 
Javascript :: when modal close event 
Javascript :: sublime node 
Javascript :: javascript onclick select coordinates 
Javascript :: js Date(date).toLocaleString() MINUUTES 
Javascript :: regex expression for password validation form validation 
Javascript :: sequelize where more than 
Javascript :: js get sum by key 
Javascript :: firebase for vue project 
Javascript :: dynamic event listener jquery 
Javascript :: append child at the top 
Javascript :: sleeping in js 
Javascript :: jquery select self and siblings 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =