h2qutc / angular-material-components

Angular Material Library provide extra components for every project
https://h2qutc.github.io/angular-material-components/
MIT License
331 stars 162 forks source link

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

Open MatthewLHolden opened 3 years ago

MatthewLHolden commented 3 years ago

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.

mvarendorff commented 3 years ago

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';
AmirovQodir commented 2 years ago

In where should I do this?

dogmaxpeppe commented 1 year ago

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

frostedpenguin commented 1 year ago

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