I'm trying to convert 12 hour string to 24 Date object
day.from = day.from || moment("6:00", ["h:mm"]).format("HH:mm");
but I'm getting this error:
angular.js:11706 Error: [ngModel:datefmt] Expected `6:00` to be a date
any idea please?
I'm trying to convert 12 hour string to 24 Date object
day.from = day.from || moment("6:00", ["h:mm"]).format("HH:mm");
but I'm getting this error:
angular.js:11706 Error: [ngModel:datefmt] Expected `6:00` to be a date
any idea please?
The error message makes me think that your date.from
should be a Date object instead of a String. Note that format
returns a String.
To get a Date object from moment you can use toDate()
, so you will have the following code:
day.from = day.from || moment("6:00", "h:mm").toDate();
PS. You don't need an array of formats when parsing your String since you have only one element inside it, that's why I used "h:mm"
instead of ["h:mm"]
.