In my form, I am using
<input type="datetime-local" ng-bind="course.endDate"..
to set a model variable. Before sending the date to the server, I need to convert the date 2015-04-04T22:00:00.000Z
to an integer
using getTime()
.
In the controller, I added the following code:
course.endDate = course.endDate.getTime();
. While this works for the server side, Angular throws an error in the console which can be seen here. (Although it works, I want to prevent errors)
Error: [ngModel:datefmt] Expected `1325458800000` to be a date
http://errors.angularjs.org/1.3.15/ngModel/datefmt?p0=1325458800000
at REGEX_STRING_REGEXP (angular.js:63)
at Array.<anonymous> (angular.js:19938)
at Object.ngModelWatch (angular.js:23419)
at Scope.$get.Scope.$digest (angular.js:14300)
at Scope.$get.Scope.$apply (angular.js:14571)
at done (angular.js:9698)
at completeRequest (angular.js:9888)
at XMLHttpRequest.requestLoaded (angular.js:9829)
How can I resolve this issue?
I had the idea of adding some fields in the form (formEndDate
) and converting it to another field (endDate = formEndDate.getTime()
) for the server side. However, this approach leads to the server rejecting the call since the parameter formEndDate
is not allowed, and removing the formEndDate
breaks everything.
Additional Problem: When I retrieve data from the server, I have an integer that needs to be converted into a date for use in the form. I must convert the date before enabling editing. Is there a way to accomplish this without iterating over the entire array of fetched data?
Solution
Thanks to the helpful responses, I have managed to solve the issue with the form when editing. I created an additional field to use when editing the form (I utilize inline editing).
I have shared a gist here