导入每个组件,但是我想要一个解决方案,其中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当我面临同样的问题时,该视频可能会为您提供帮助。