ng-matero / extensions

Angular Material Extensions Library.
https://ng-matero.github.io/extensions/
MIT License
393 stars 48 forks source link

MtxDatetimePicker not populated when the recieved date is as string #235

Closed vmuresanu closed 10 months ago

vmuresanu commented 10 months ago

Description: When receiving date as iso string, date picker value is not populated. One real scenario is that all dates from BE are as string.

Expected: Date is being populated

Reproduction: https://stackblitz.com/edit/stackblitz-starters-u7c3h8?description=An%20angular-cli%20project%20based%20on%20@angular/animations,%20@angular/common,%20@angular/compiler,%20@angular/core,%20@angular/forms,%20@angular/platform-browser,%20@angular/platform-browser-dynamic,%20@angular/router,%20core-js,%20rxjs,%20tslib%20and%20zone.js&file=src%2Fmain.ts,src%2Fmain.html,angular.json,src%2Fglobal_styles.scss&title=Angular%20Starter

Note: There are two components in the stackblitz example, one of them is the Datepicker from Angular Material, and notice that the control value is populated both as string and as Date. However if we change the formControl value to: control = new FormControl(new Date('2023-04-08T18:51:00.000Z')); both pickers are populated

nzbin commented 10 months ago

Maybe you should use moment or any other adapter instead of MtxNativeDatetimeModule. Please check https://github.com/ng-matero/extensions/issues/141

vmuresanu commented 10 months ago

I tried DateFns adapter instead, and it works. However, I think that this is still a bug in NativeDatetimeAdapter. Even though Angular team strongly recommends to use a date library, it should be perfectly fine to stick to the Native one.