如何在独立组件中动态更新mat-datepicker语言? 我需要在全球和动态上翻译我所有的杂物日期。我所有的组件都是独立的,我有一种工具。当我将此指令导入每个组件时,它起作用b ...

问题描述 投票:0回答:0
指导

导入每个组件,但是我想要一个解决方案,其中i不必将此指令添加到每个独立的组件中。我正在使用角18. -date-local.Diractive.ts @Directive({ selector: '[matDatepicker]', standalone: true, }) export class DateLocaleDirective implements OnDestroy { constructor(private dateAdapter: DateAdapter<Date>, private translateService: TranslateService) { this.dateAdapter.setLocale(this.translateService.currentLang); this.translateService.onLangChange.subscribe((event: LangChangeEvent) => { console.log("event.lang", event.lang); this.dateAdapter.setLocale(event.lang); }); } }

将我的自定义指令置于独立组件(以这种方式工作,但我不想要这个解决方案

@Component({ selector: 'app-home-page', standalone: true, imports: [ DateLocaleDirective ], templateUrl: './home.component.html' })
可以在root/globally上更新所有的mat-datepickers?

https://www.youtube.com/watch?v =ztibukfy3jm
当我面临同样的问题时,该视频可能会为您提供帮助。

angular angular-material ngx-translate
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.