我是Angular和Angular Material的新手 .
对于我的后端希望它是zonedDate格式的日期 . (例如:2018-04-11T02:12:04.455Z [UTC])
所以我在上面的格式中获得了 Value ,它没有绑定到mat-datepicker .
这是html代码:
<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>
所以这里ngModel没有绑定到datepicker的值 .
经过一番观察,我意识到:
值为“ 2018-04-11T02:12:04.455Z[UTC] ”的日期是 binding 到datepicker .
值为“ 2018-04-02T14:00Z[UTC] ”的日期是 not binding 到datepicker .
有什么建议吗?
1 回答
所以,基本上,你可以用javascript函数 toISOString() 转换这个日期 .
或者只是通过创建 new Date() 对象 .
在我的情况下,日期转换为一些错误的格式,因此得到一个错误 .