0

How can I control the format of input for a datepicker individually, without changing format for the whole module?

<input matInput [matDatepicker]="dp" [formControl]="date" [format]="'DD/MM/YYYY'"> <-- is this possible?
<mat-datepicker-toggle matSuffix [for]="dp"></mat-datepicker-toggle>
<mat-datepicker #dp></mat-datepicker>
Jango
  • 115
  • 1
  • 8
  • 1
    you can change the DateAdapter for one component, e.g. https://stackoverflow.com/questions/54113765/angular-material-date-picker-input-treat-the-date-as-us-format/54117664#54117664. But I'm not prety sure how do if you has two datePicker in the same component – Eliseo Jun 07 '20 at 10:31

1 Answers1

0

Yes, you have to change locale of date-picker to en-GB by adding {provide: MAT_DATE_LOCALE, useValue: 'en-GB'} to provider section of you module. Like below

@NgModule({providers: [{provide: MAT_DATE_LOCALE, useValue: 'en-GB'}]})

Official doc for this

  • I want to format multiple inputs within the same module differently. If I do what you suggest, then every datepicker input will have the same format. What I asked is whether it is possible to format datepicker inputs individually. – Jango Jun 07 '20 at 10:09