angular-material-components icon indicating copy to clipboard operation
angular-material-components copied to clipboard

Question: DateTimePicker - Is there a way to use `setLocale` like the native Angular Material Date Picker?

Open MatthewLHolden opened this issue 4 years ago • 4 comments

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.

MatthewLHolden avatar Feb 08 '21 14:02 MatthewLHolden

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';

mvarendorff avatar Feb 24 '21 14:02 mvarendorff

In where should I do this?

AmirovQodir avatar Jun 10 '22 16:06 AmirovQodir

I think this thread should be closed. I resolved the same problem with @geisterfurz007 solution.

dogmaxpeppe avatar Sep 22 '23 10:09 dogmaxpeppe

updated the docs with this workaround in #364, had a hard time implementing custom locales 😿

frostedpenguin avatar Oct 25 '23 12:10 frostedpenguin