Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to add toaster in angular 9

npm install ngx-toastr --save
Comment

Toast message angular

import { ToastrService } from 'ngx-toastr';
Comment

Toast message angular

npm install ngx-toastr --save
npm install @angular/animations --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

Toast message angular

"styles": [
   "src/styles.css",
   "node_modules/ngx-toastr/toastr.css"
]
Comment

PREVIOUS NEXT
Code Example
Javascript :: append array js 
Javascript :: An external JavaScript cannot contain the <script tag 
Javascript :: how to add numbers in an array in javascript 
Javascript :: js array two dimensional 
Javascript :: jquery check if class exists 
Javascript :: foreach loop in react 
Javascript :: js reduce break 
Javascript :: js get clipboard data 
Javascript :: vowel 
Javascript :: left join in sequelize 
Javascript :: chrome storage onchanged 
Javascript :: open cypress window 
Javascript :: route pass props to component 
Javascript :: regexp object js 
Javascript :: angular set content type 
Javascript :: generate a random id 
Javascript :: javascript disable form 
Javascript :: MVC 5 controller return json value to view 
Javascript :: js random string from array 
Javascript :: filter array inside array 
Javascript :: ngswitchcase in angular 8 
Javascript :: Javascript how to differentiate single click event and double click event 
Javascript :: add sass to react 
Javascript :: custom attribute jquery selector 
Javascript :: allow only numbers and special characters in textbox using javascript 
Javascript :: capitalize first letter of string javascript 
Javascript :: convert json string or parse 
Javascript :: canvas js filter greyscale 
Javascript :: angular get current route 
Javascript :: check if input is valid js 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =