Ngx-toastr: Changing the configuration of iconClasses seems not to work via forRoot but only via injection

Created on 31 May 2017  路  3Comments  路  Source: scttcper/ngx-toastr

First of all: Very nice piece of software!
Now what confused me:

ToastrModule.forRoot(
      {
        iconClasses: {
          error: 'toast-error-ABC'
        }
      }
    )

does not work as expected - keeps the default value 'toast-error'
as can be seen in src/app.ts here:
https://embed.plnkr.co/ABCkco3p3JYYeBEXxiNA/

export class AppModule {
  constructor(toastrConfig: ToastrConfig) {
    toastrConfig.iconClasses.error = 'toast-error-ABC';
  }
}

works just fine - the default value is replaced with 'test-error-ABC'
as can be seen in src/app.ts here:
https://embed.plnkr.co/MQa4myRfs4GotrnOlLrZ/

If the first example can't work/is intentionally a little hint in the section "Override default settings" could save others some headscratching.

Cheers

(1) easy bug

Most helpful comment

Just quickly looking through the source. I believe the issue happens at https://github.com/scttcper/ngx-toastr/blob/master/src/lib/toastr/toastr-config.ts#L92-L95

The statements should probably be reversed so that it uses the passed in value, if it exists, instead of if the class property has a value (which is always true). I can't make a pull request until a bit later so if there still isn't one open I'll go ahead and open one when I'm able.

All 3 comments

Just quickly looking through the source. I believe the issue happens at https://github.com/scttcper/ngx-toastr/blob/master/src/lib/toastr/toastr-config.ts#L92-L95

The statements should probably be reversed so that it uses the passed in value, if it exists, instead of if the class property has a value (which is always true). I can't make a pull request until a bit later so if there still isn't one open I'll go ahead and open one when I'm able.

We looked at the sources as well - but since we are pretty new to TypeScript we obviously didn't look properly...
Thanks for taking care of it!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sollygit picture sollygit  路  7Comments

quirogamauricio picture quirogamauricio  路  3Comments

harikrishnan-u01 picture harikrishnan-u01  路  6Comments

crhistianramirez picture crhistianramirez  路  5Comments

picninim picture picninim  路  6Comments