I'm using a mat-date-rang-input of Angular Material. I changed the date format of Angular Material from MM/dd/yyyy to dd/MM/yyyy, and that's works alright.
<mat-form-field ngClass="filters_dateInterval">
<mat-label>Date interval</mat-label>
<mat-date-range-input [rangePicker]="picker" md-date-locale="{
inputDisplay: dd/MM/yyyy
}}">
<input matStartDate placeholder="Início" [(ngModel)]="dateStartFilterField" (valueChanges)="show($event)" />
<input matEndDate placeholder="Fim" [(ngModel)]="dateEndFilterField" />
</mat-date-range-input>
<mat-datepicker-toggle matSuffix [for]="picker" ngClass="filters_dateInterval__icon"></mat-datepicker-toggle>
<mat-date-range-picker #picker></mat-date-range-picker>
</mat-form-field>
However, when I tested the ui/ux, I noticed something unusual. After I wrote a date in the format dd/MM/yyyy and focused out, it lost that format and the date changed to the format MM/dd/yyyy.
I tried changing the app.module.ts to include a provider to format the date.
providers: [
{
provide: LOCALE_ID,
useValue: DATE_FORMAT_PTBR
}
]
This is my DATE_FORMAT_PTBR:
export const DATE_FORMAT_PTBR = {
parse: {
dateInput: 'dd/MM/yyyy',
},
display: {
dateInput: 'dd/MM/yyyy',
monthYearLabel: 'MMMM YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MMMM YYYY'
},
formater: {
dateInput: 'dd/MM/yyyy',
}
};
I tried changing the useValue of providers to 'pt-BR' too, but it did not affect the situation.