I'm new to Angular and I just jumped into an existing project. My issue is about a date picker from angular material. If I select a date via the toggle, no issue, the date is correct but if I want to put a date manually (format used : dd/MM/yyyy), it automatically switch dd and MM as I focus out the input field.
So for example, If I type : "07/04/2019", then I click on the next input I want to change, the date changes to "04/07/2019".
Here is the Input :
<mat-form-field>
<input matInput [matDatepicker]="availableFrom" placeholder="From" formControlName="availableFrom" (dateChange)="fromDateLessThanToDate()">
<mat-datepicker-toggle matSuffix [for]="availableFrom"></mat-datepicker-toggle>
<mat-datepicker #availableFrom></mat-datepicker>
</mat-form-field>
fromDateLessThanToDate() {
if (DateUtils.fromDateLessThanToDate(this.conventionForm.value.availableFrom, this.conventionForm.value.availableTo))
this.error_date = { isError: true, errorMessage: 'To date can\'t before From date' };
else
this.error_date = { isError: false, errorMessage: '' };
}
When we arrive in fromDatLessThanToDate()
function, the date (this.conventionForm.value.availableFrom
) already has a wrong value (days and months switched). I already tested some solutions like this Angular Material mat-datepicker (change) event and format but the result is the same.