angular-material-components icon indicating copy to clipboard operation
angular-material-components copied to clipboard

Angular Material 14 / TypeScript 4.8.4 : date.getHours is not a function

Open DavidRobertKeller opened this issue 3 years ago • 0 comments

Hello,

I have defined this component:

                  <ngx-mat-timepicker [(ngModel)]="myDatetime"></ngx-mat-timepicker>

and I have this error:

       ERROR Error: Uncaught (in promise): TypeError: date.getHours is not a function
TypeError: date.getHours is not a function
    at NgxMatNativeDateAdapter.getHour (angular-material-components-datetime-picker.mjs:3044:21)
    at NgxMatTimepickerComponent._updateHourMinuteSecond (angular-material-components-datetime-picker.mjs:1731:39)
    at NgxMatTimepickerComponent.writeValue (angular-material-components-datetime-picker.mjs:1694:14)

In your code:

    invalid() {
        return new Date(NaN);
    }
    getHour(date) {
        return date.getHours();
    }
    getMinute(date) {
        return date.getMinutes();
    }

DavidRobertKeller avatar Oct 14 '22 13:10 DavidRobertKeller