1

Hello in my angular material application, I am using mat-datepicker with a moment date adapter. I need keep selected date value as ISO string (2020-08-14T00:00:00.000Z), but I can't simply bind a property to datepicker with ngModel ([(ngModel)]="selectedDate"), because when I use this, datepicker fill selectedDate with moment object, after the date was selected. For ISO string I must use [ngModel]="selectedDate" (dateChange)="selectedDate = $event.value.toISOString()" on every mat-datepicker. Is there any way to set this globally so that the datepicker returns automatically an ISO string and I can use simply [(ngModel)]?

Thanks for your help.

Jakub
  • 11
  • 1
  • Take a look at this https://stackoverflow.com/a/53359773/10832136 – Kars Aug 14 '20 at 21:02
  • This works on formatting the date, which is displayed in the datepicker input field, but in the variable selectedDate that is assigned to [(ngMode)]l, there is still a moment object. – Jakub Aug 15 '20 at 21:15

0 Answers0