我正在为我的Angular 6项目使用ngx-bootstrap datepicker,我需要使用意大利语语言环境;与官方指南(https://valor-software.com/ngx-bootstrap/#/datepicker#locales)我想出了这个问题,现在我的日期采访看起来像意大利语,但我有另一个问题。
要在意大利语中使用datepicker,我必须在每个组件中导入BsLocaleService并在onInit函数中使用_localeService.use('it')方法;我的问题是,我可以在我的应用程序中全局查看意大利语语言环境,而无需调用函数在每个组件中设置语言环境吗?
我试图在AppComponent中使用set locale函数,但它不起作用。
多谢你们
对于未来的读者,这就是我这样做的方式:
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');
}
}