Angular Material - Date Picker changes the date when taking input focus

Asked

Viewed 136 times

-1

I am facing problems at Angular. I am using angular material for some /components and I am using datepicker. My date locale is already 'pt', it even appears the name of the months in Portuguese and such. But when I type in the input 11/08/1997 and click out of the input, it changes to 08/11/1997. I tried everything here but could not.

  • Could you put an excerpt of the code to make it easier to understand the problem? You are using momentjs?

1 answer

0


Get it sorted by putting it in my module:

import { MatNativeDateModule, MAT_DATE_FORMATS } from '@angular/material';
import { MomentDateModule } from '@angular/material-moment-adapter';

...

providers: [
  {
    provide: MAT_DATE_FORMATS,
    useValue: {
      parse: {
        dateInput: ['l', 'LL'],
      },
      display: {
        dateInput: 'L',
        monthYearLabel: 'MMM YYYY',
        dateA11yLabel: 'LL',
        monthYearA11yLabel: 'MMMM YYYY',
      },
    },
  }
]

and my input component

import { DateAdapter } from '@angular/material';
    ngOnInit() {
    this.dateAdapter.setLocale('pt-br');
  }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.