Ngx-bootstrap: BsDatepickerModule base config

Created on 1 Dec 2017  路  7Comments  路  Source: valor-software/ngx-bootstrap

How set base config for BsDatepickerModule ?

Most helpful comment

Just tell the providers to use the config function:

export function getDatepickerConfig(): BsDatepickerConfig {
  return Object.assign(new BsDatepickerConfig(), {
    containerClass: 'theme-blue',
    dateInputFormat: 'DD/MM/YYYY'
  });
}

@NgModule({
  ...
  providers: [{ provide: BsDatepickerConfig, useFactory: getDatepickerConfig }]
})

All 7 comments

via using BsDatepickerConfig, such general question better to ask via Stack Overflow
but I made a note about missing sample
https://valor-software.com/ngx-bootstrap/#/datepicker#bs-datepicker-config

How do this for all datepickers in my app?

@valorkin Sorry to ask here, but can't find (noob in angular4) a way to set a global configuration. And the only way I found was using a service and configuring each one with the [bsConfig] input.
Any hint? Thanks for this!

Documentation about this common use case is very limited it seems ...

Just tell the providers to use the config function:

export function getDatepickerConfig(): BsDatepickerConfig {
  return Object.assign(new BsDatepickerConfig(), {
    containerClass: 'theme-blue',
    dateInputFormat: 'DD/MM/YYYY'
  });
}

@NgModule({
  ...
  providers: [{ provide: BsDatepickerConfig, useFactory: getDatepickerConfig }]
})

I can't get this to work on a global level in a large app with multiple lazy-loaded modules. It looks like I have to repeat this in every child module, rather than once in the main module. Any work arounds?

@whafrog
gufigueiredo solution works fine with lazy loaded modules. Just add it to app.module.ts (tested on Angular 9, ngx-bootstrap 5.5.0)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RolfVeinoeSorensen picture RolfVeinoeSorensen  路  3Comments

juanitavollmering picture juanitavollmering  路  3Comments

KimBum picture KimBum  路  3Comments

phmello picture phmello  路  3Comments

srjkrl20011991 picture srjkrl20011991  路  3Comments