简体   繁体   中英

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

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');
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM