silversoul
silversoul

Reputation: 33

Angular 6 ngx-bootstrap Datepicker global locale

I'm using the ngx-bootstrap datepicker for my Angular 6 project and I need to use the italian locale; with the official guide (https://valor-software.com/ngx-bootstrap/#/datepicker#locales) i figured out this problem and now my datepickers look in italian, but I have another problem.

To have datepicker in italian, I had to import in every component the BsLocaleService and use in the onInit function the _localeService.use('it') method; my question is, can I se globally the italian locale in my app, without call the function to set locale in every component?

I tried to use the set locale function in the AppComponent, but it doesn't work.

Thanks guys

Upvotes: 1

Views: 2767

Answers (1)

Henrique Campos
Henrique Campos

Reputation: 561

For future readers, this is how i did this:

import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";

import { BsDatepickerModule } from "ngx-bootstrap";
import { BsLocaleService } from 'ngx-bootstrap/datepicker';
import { defineLocale } from 'ngx-bootstrap/chronos';
import { itLocale } from 'ngx-bootstrap/locale';

import { MyComponent } from "./my.component";

@NgModule({
    imports: [CommonModule, BsDatepickerModule.forRoot()],
    declarations: [MyComponent],
    providers: []
})
export class MyModule {
    constructor(localeService: BsLocaleService) {
        defineLocale('it', itLocale);
        localeService.use('it');
    }
}

Upvotes: 5

Related Questions