jfmdev / ngComboDatePicker

Angular directive to select dates using combo boxes
Mozilla Public License 2.0
23 stars 20 forks source link

modelValue.getDate is not a function #34

Closed Millen31 closed 7 years ago

Millen31 commented 7 years ago

Hello,

I'm using the combodatepicker in a Modal. If i open the modal the first time, the valueModel has a correct date format

ngModelCtrl.$formatters.push(function(modelValue) { modelValue = Sun May 15 2016 14:00:00 GMT+0200 (Mitteleuropäische Sommerzeit) {}

If I open the Modal again the modelValue is not correct anymore and I get a error (modelValue.getDate is not a function)

ngModelCtrl.$formatters.push(function(modelValue) { modelValue = "2016-05-15T14:00:00.000Z"

Do I have to change something in my object or do I have to pass my date object in another format to the front end?

Thanks!

Best regards

jfmdev commented 7 years ago

Hi Millen,

Could you paste a copy (or at least a fragment) of your code? I'm not really sure what are you doing for getting this error.

Regards

jfmdev commented 7 years ago

Closed due to inactivity

ajayreddy56 commented 7 years ago

@jfmdev am facing the same Bro .when i update the date getting same issue.(while creating no problem)

ajayreddy56 commented 7 years ago

while update in html:

<ng-combo-date-picker
                              ng-placeholder="Year,Month,Date"
                              ng-max-date="{{ maxYear + '-12-31' }}"
                              ng-attrs-date='{"class": "form-control"}' ng-attrs-month='{"class": "form-control"}' ng-attrs-year='{"class": "form-control"}'
                              ng-attrs-date='{"name": "day"}' ng-attrs-month='{"name": "month"}' ng-attrs-year='{"name": "year"}'
                              ng-model="aboutme.dateOfBirth"
                              ng-required="true">
                </ng-combo-date-picker>
js:
$scope.update=function(){
var user = res.data;
$scope.aboutme= {"dateOfBirth":user.dateOfBirth};
AppUserService.updateAboutMe(user,function(response){},function(){}
};
jfmdev commented 7 years ago

This is not an error in the library, but an error in your code: the value assigned to ngModel must be an instance of the Date class, not an integer.

In order to fix your code you can simply do:

$scope.aboutme = {"dateOfBirth": new Date(user.dateOfBirth) };