答案 0 :(得分:0)
创建服务。
import { MatDatepicker } from '@angular/material';
import { CustomTranslateService } from '@ngx-translate/core';
import { Injectable } from '@angular/core';
const OPEN_CALENDAR = 'Open Calendar';
@Injectable()
export class CustomMatDatePickerService extends MatDatepicker {
public constructor(private translate: CustomTranslateService) {
super();
this.translate.onLangChange.subscribe((e: Event) => {
this.getAndInitTranslations();
});
this.getAndInitTranslations();
}
openCalendarLabel = this.translate.translations[this.translate.store.currentLang][OPEN_CALENDAR];
public getAndInitTranslations(): void {
this.translate.get([
OPEN_CALENDAR
])
.subscribe((translation: any) => {
this.openCalendarLabel = translation[OPEN_CALENDAR];
this.changes.next();
});
}
}