tabuckner / material-dayjs-adapter

A MatDateAdapter for Dayjs
https://www.npmjs.com/package/@tabuckner/material-dayjs-adapter
15 stars 23 forks source link

An issue with changing a locale in a lazy-loaded module #22

Closed mazdok closed 3 years ago

mazdok commented 3 years ago

First thanks a lot for this package. This actually not a bug report but rather asking for advice. I've been struggling with this problem for a couple of days already...

I have a problem when I try to trigger locale change from my singleton service for a lazy-loaded module. All works fine when it's an eagerly loaded component.

In a service I inject DateAdapter and do on a language change:

dayjs.locale(locale);
this._dateAdapter.setLocale(locale);

It works initially but when I want dynamically change a locale then it doesn't work.

Modified example here - https://github.com/mazdok/angular_datepicker_dayjs_adapter_example/tree/master/projects/example-material-dayjs-adapter.

A stackblitz example (not mine but same problem) - https://stackblitz.com/edit/angular-4cu4cb?file=src%2Fapp%2Fdatepicker%2Fcustom-date-adapter.ts

mazdok commented 3 years ago

In case anyone else had same issue - here is a StackOverflow answer which helped me to solve this https://stackoverflow.com/questions/50666556/language-switch-for-angular-material-datepicker-in-lazy-loaded-module.

And StackBlits demo - https://stackblitz.com/edit/angular-6vupnn?file=src%2Fapp%2Fdatepicker%2Fcustom-date-adapter.ts