Search code examples
angulartoastr

Where could I put a ngx-toastr config file?


I'm very new to Angular, and started working on some existing project.

It has "ngx-toastr": "~10.0.2" among the package.json dependencies, and I'd need to change some of its default parameters.

What I currently have :

this.toastr.success('Message');

What works for a single call :

  this.toastr.success('Message', null, {
    timeOut: 1000,
    extendedTimeOut: 1
  });

I couldn't find any place explaining how to change the default values. Neither here, nor in the tutorials I found.

Is it so obvious no one feels necessary to mention it ? What did I miss ?


Solution

  • As MikeOne pointed out, the Angular modules config is located in app.module.ts
    Here is a code sample from his link demonstrating how to do it:

    import { BrowserModule } from '@angular/platform-browser';
    import { ToastContainerModule, ToastrModule } from 'ngx-toastr';
    // [...]
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        BrowserAnimationsModule,
    // Default module configuration can be tweaked here //
        ToastrModule.forRoot({
          timeOut: 10,
          progressBar: true,
          positionClass: 'toast-bottom-right'
        }),
        ToastContainerModule
      ],
      providers: [],
      bootstrap: [ AppComponent ]
    })
    export class AppModule { }
    // [...]