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 :: build url query string javascript 
Javascript :: leaflet circle get bounds 
Javascript :: linking html with javascript 
Javascript :: reset page js 
Javascript :: react add class to each children 
Javascript :: jquery option not disabled 
Javascript :: using async function in useeffect 
Javascript :: what is status 400 in react 
Javascript :: get id of an element 
Javascript :: use get_json in jstree example 
Javascript :: how to play audio in javascript 
Javascript :: ISS proxy express 
Javascript :: useeffect react example 
Javascript :: leap year function javascript 
Javascript :: how to convert jsonobject to string in java 
Javascript :: jquery get all inputs in form 
Javascript :: remove special characters in javascript 
Javascript :: get position of element in react 
Javascript :: get position of element relative to document 
Javascript :: write to file but dont overwrite fs.writeFile node 
Javascript :: react 18 render 
Javascript :: express redirect with post data 
Javascript :: How to send form data from react to express 
Javascript :: node -r dotenv/config 
Javascript :: jshint ignore line 
Javascript :: dynamically change meta tags javascript 
Javascript :: js get text from html string 
Javascript :: short string javascript 
Javascript :: load external javascript file angular component 
Javascript :: what is jquery 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =