Search code examples
angulartypescriptangular-toastrngtoast

ngx-toastr ToastrService.show() type parameter Angular 2 +


I can use ToastrService.success/error/warning/info() without problem,

but when i use ToastrService.show() i don't know which correct string type i should send

i tried send a enum like this:

export enum ToastType {
    Success = 'success',
    Error = 'error',
    Info = 'info',
    Warning = 'warning'
}

but the component lose the styles.


Solution

  • Stumbled into the same issue and found the types at the docs:

    iconClasses = {
      error: 'toast-error',
      info: 'toast-info',
      success: 'toast-success',
      warning: 'toast-warning'
    };
    

    Source: https://github.com/scttcper/ngx-toastr#iconclasses-defaults

    UPDATE

    The show() method takes four parameters, where the type are the names listed above.

    ToastrService.show(message?: string, title?: string, override?: Partial<IndividualConfig>, type?: string)
    

    An example with all parameters can be seen here: https://stackblitz.com/edit/angular-uu7r6s

    Or an even more complete example: https://github.com/grabowskidaniel/exemplo-ngx-toastr

    Using NgxToastr version 10