angular 5:ngx-bootstrap timepicker locale

时间:2018-04-25 03:34:49

标签: angular timepicker ngx-bootstrap

我正在使用ngx-bootstrap的timepicker,如下所示:

 <timepicker [(ngModel)]="startDateTime" name="startTimes" #startTime="ngModel" required [showMeridian]="true"></timepicker>                                                          

根据已登录的用户,尝试让语言环境适用于'de'(Deutsche)和'ja'(Japaneese):

app.module.ts:

import {TimepickerModule, BsLocaleService} from 'ngx-bootstrap';

@NgModule({
    imports: [
        TimepickerModule.forRoot() 
    ],
    declarations: [

    ],
    providers: [
        BsLocaleService 
    ]
})

my.component.ts:

import {Component, OnInit, Inject, ViewChild, SimpleChange, SimpleChanges} from '@angular/core';
import {TimepickerModule, BsLocaleService} from 'ngx-bootstrap';
import {listLocales} from 'ngx-bootstrap';
import {deLocale} from 'ngx-bootstrap';
import {jaLocale} from 'ngx-bootstrap';

@Component({
    selector: 'my-component',
    templateUrl: './my-component.html',
    styleUrls: ['./my-component.less']
})
export class MyComponent implements OnInit {
    locale = 'ja'; //hardcoded for testing
    locales = listLocales();
    startDateTime = new Date();

    constructor(private _localeService: BsLocaleService) {
        this._localeService.use(this.locale);
    }

这不适用于区域设置,timepicker的功能正常工作。我对此很陌生,网站上的文档没有关于timepicker语言环境的任何内容。我通过查看datepicker区域设置:https://valor-software.com/ngx-bootstrap/#/datepicker#locales

实现了此功能

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我认为你应该在模块中添加这篇文章

// imports

import { defineLocale, jaLocale } from 'ngx-bootstrap';

defineLocale('ja', jaLocale);

// @NgModule(...)