【问题标题】:angular 5: ngx-bootstrap timepicker locale角度 5:ngx-bootstrap 时间选择器语言环境
【发布时间】:2018-04-25 03:34:48
【问题描述】:

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

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

尝试根据这样的登录用户使语言环境适用于'de'(德意志)和'ja'(日语):

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

我做错了什么?

【问题讨论】:

    标签: angular timepicker ngx-bootstrap


    【解决方案1】:

    我认为你应该在模块中添加这件作品

    // imports
    
    import { defineLocale, jaLocale } from 'ngx-bootstrap';
    
    defineLocale('ja', jaLocale);
    
    // @NgModule(...)
    

    【讨论】:

    • 这可以在功能模块中还是应该在 app.module 中?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-29
    • 1970-01-01
    相关资源
    最近更新 更多