angular-material-components
angular-material-components copied to clipboard
Question: DateTimePicker - Is there a way to use `setLocale` like the native Angular Material Date Picker?
I had an older component that used the Angular Material Date picker. Based on a database value, the locale would be updated for the date picker. Upon installing the Angular Material Components Date Time Picker, this no longer seems to work. As a test i created a method to try and manually call the locale change:
setLocale(val){
this.locale = val;
this.dateAdapter.setLocale(val);
}
This doesn't work. Is there a way to change the locale of the DateTimePicker? I'm not using moment js within my application. Any assistance would be greatly appreciated.
Just a guess: Are you using the "correct" DateAdapter? The code below works fine for me and also appears to work when the locale is changed outside of the constructor (I created a quick and dirty red div with a click listener to try it out).
constructor(private adapter: NgxMatDateAdapter<Date>) {
adapter.setLocale('de-DE');
}
The import is
import {NgxMatDateAdapter} from '@angular-material-components/datetime-picker';
In where should I do this?
I think this thread should be closed. I resolved the same problem with @geisterfurz007 solution.
updated the docs with this workaround in #364, had a hard time implementing custom locales 😿