Angular 如何将npx引导日期选择器语言更改为pt br?
我在Angular 4中做一个项目,我安装了ngx引导程序,日期选择器是英文的。我在app.module.ts中插入了以下行:Angular 如何将npx引导日期选择器语言更改为pt br?,angular,typescript,datepicker,components,ngx-bootstrap,Angular,Typescript,Datepicker,Components,Ngx Bootstrap,我在Angular 4中做一个项目,我安装了ngx引导程序,日期选择器是英文的。我在app.module.ts中插入了以下行: import { defineLocale } from 'ngx-bootstrap/chronos'; import { ptBrLocale } from 'ngx-bootstrap/locale'; defineLocale('pt-br', ptBrLocale); 然后我进入页面的组件,在那里我调用了我的日期选择器,我进行了导入并声明: import
import { defineLocale } from 'ngx-bootstrap/chronos';
import { ptBrLocale } from 'ngx-bootstrap/locale';
defineLocale('pt-br', ptBrLocale);
然后我进入页面的组件,在那里我调用了我的日期选择器,我进行了导入并声明:
import { Component, OnInit } from '@angular/core';
import { BsDatepickerConfig, BsLocaleService } from 'ngx-bootstrap/datepicker';
import { listLocales } from 'ngx-bootstrap/chronos';
及
但它仍然不起作用。我做错了什么?代码的问题是,您将更改区域设置的调用放在另一个函数中,而您没有调用它 尝试删除applyLocale函数并将更改区域设置的调用放入构造函数中,如下所示:
@Component({
selector: 'demo-datepicker-change-locale',
templateUrl: './cancelar-agendamentos-consulta.component.html'
})
export class DemoDatepickerChangeLocaleComponent {
locale = 'pt-br';
locales = listLocales();
constructor(private _localeService: BsLocaleService) {
this._localeService.use(this.locale);
}
}
所以我希望语言是意大利语,我用以下代码更改了语言: 我输入:
从“ngx引导”导入{BsLocaleService,defineLocale,itLocale};
example.component.ts中的代码
//日期选择器的设置语言
setDatepickerLanguage(){
定义刻度(“it”,itLocale);
this.localeService.use('it');
}
并调用构造函数()上的函数
它成功了
截图:
@Component({
selector: 'demo-datepicker-change-locale',
templateUrl: './cancelar-agendamentos-consulta.component.html'
})
export class DemoDatepickerChangeLocaleComponent {
locale = 'pt-br';
locales = listLocales();
constructor(private _localeService: BsLocaleService) {
this._localeService.use(this.locale);
}
}