javascript - AngularJS convert Date to getTime() before sending to server -
i have form uses <input type="datetime-local" ng-bind="course.enddate"..
, sets variable of model. before sending date server i've convert date 2015-04-04t22:00:00.000z
integer
given gettime()
.
in controller added this: course.enddate = course.enddate.gettime();
works server side angular complains in console this error. (as said, works, avoid errors)
error: [ngmodel:datefmt] expected `1325458800000` date http://errors.angularjs.org/1.3.15/ngmodel/datefmt?p0=1325458800000 @ regex_string_regexp (angular.js:63) @ array.<anonymous> (angular.js:19938) @ object.ngmodelwatch (angular.js:23419) @ scope.$get.scope.$digest (angular.js:14300) @ scope.$get.scope.$apply (angular.js:14571) @ done (angular.js:9698) @ completerequest (angular.js:9888) @ xmlhttprequest.requestloaded (angular.js:9829)
how can then?
i had idea of adding fields used in form (formenddate
) , convert 1 (enddate = formenddate.gettime()
) server side, in way server refuse call since parameter formenddate
not allowed, , if remove formenddate
breaks.
additional problem: when fetch data server have integer needs converted date used in form. i've convert date before allowing edit. how can this? (the data fetched array, terrific have conversion without having iterate on whole array)
solution
thanks 2 answers (i set correct first came) (somehow) solved problem of form when editing. did creating field , use form when editing (i inline editing).
i created gist here
before sending data server, make copy , set enddate
. send copy server:
var coursecopy = angular.copy(course); coursecopy.enddate = coursecopy.enddate.gettime();
Comments
Post a Comment