小编Nic*_*bro的帖子

尝试在用户更改页面语言时翻译 NgPickDateTime 标签

我在我的 Angular 应用程序 ( https://danielykpan.github.io/date-time-picker/ ) 中使用 NgPickDatetime,当我尝试翻译标签和消息时遇到问题。我按照文档中的说明操作,它工作正常,但问题是当我更改站点语言时,标签仍然使用以前的语言。

我的代码是:

日期时间-locale.module.ts:

import { NgModule } from '@angular/core';
import { OwlDateTimeModule, OwlNativeDateTimeModule, OwlDateTimeIntl} from 'ng-pick-datetime';
import { DefaultIntl } from './datepicker-locale.component';


@NgModule({
    imports: [OwlDateTimeModule, OwlNativeDateTimeModule],
    providers: [
        {provide: OwlDateTimeIntl, useClass: DefaultIntl},
    ],
})
export class DateTimeLocaleModule {
}
Run Code Online (Sandbox Code Playgroud)

datepicker-locale.component.ts:

import { OwlDateTimeIntl } from 'ng-pick-datetime';

export class DefaultIntl extends OwlDateTimeIntl {
    public cancelBtnLabel = 'Annuleren';
    public setBtnLabel = 'Opslaan';
    private currentLang;

    constructor() {
        super();

        this.getLang();
    }

    public getLang() {
        this.currentLang = JSON.parse(localStorage.getItem("language")); …
Run Code Online (Sandbox Code Playgroud)

javascript ngx-translate angular angular5 angular6

2
推荐指数
1
解决办法
2072
查看次数

标签 统计

angular ×1

angular5 ×1

angular6 ×1

javascript ×1

ngx-translate ×1