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

2.9k Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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

0
On

I use ToasterService like this,

this._toasterService.openToast("", "update success!", "success");

this._toasterService.openToast("", "update error!", "error");