I am very new to Angular and Angular Material.
For the dates my backend wants it to be in zonedDate Format. (e.g.: 2018-04-11T02:12:04.455Z[UTC])
So I am getting value in the above format, which is not binding to mat-datepicker.
Here is html code:
<mat-form-field class="fx-cell-1" floatLabel="never">
<input matInput name="myDate" [matDatepicker]="myDate" placeholder="Date of Expense"
[(ngModel)]="myDate" #myDate="ngModel" [max]="maxDate" required >
<mat-datepicker-toggle matSuffix [for]="myDate"></mat-datepicker-toggle>
<mat-datepicker #myDate></mat-datepicker>
</mat-form-field>
So here ngModel is not binding value to datepicker.
After some more observation, I realized that:
The date with value "2018-04-11T02:12:04.455Z[UTC]" is binding to the datepicker.
The date with value "2018-04-02T14:00Z[UTC]" is not binding to the datepicker.
Any suggestion???
new Date('myDate')
before using it in your datepicker? – Olivernew Date()
, but both saying Invalid Date. After removing the[UTC]
from the string, both would be correctly read as a date time instance in UTC time. So simply strip of the brackets part and everything should work. – Oliver