Add Toastr To Angular App

علی ذوالفقار
1400/06/03 10:48:40 (713)
// install 
npm install ngx-toastr --save  
// install 
npm install @angular/animations --save   

// add this tow line in app.module.ts 
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';    
import { ToastrModule } from 'ngx-toastr'; 

// add this to import section in app.module.ts 
imports: [  
    BrowserModule,  
    AppRoutingModule, 
    BrowserAnimationsModule,  
    ToastrModule.forRoot({
    })  
  ],  

// add this line into style.css 
@import '~ngx-toastr/toastr.css';  


// use as this : 
// first import 
import { ToastrService } from 'ngx-toastr';      

// then inject in constructor 
  constructor(private toastr: ToastrService) { }  

// then use like this : 
    this.toastr.success("Toastr Success message",'Success') 

// you can change config of the toastr in app.module.ts 
ToastrModule.forRoot({  
        positionClass:'top-left',  
        closeButton: true,  
        })  

Back