0

I have a form to submit data. I have one Date field in that form. All is working fine. But when i try to retrieve data to update including date. i get error "ngModel:datefmt". I have tried converting date formats in database YY-mm-dd and dd-mm-yy. I have tried converting date formats in JavaScript to yy-mm-dd and dd-mm-yy. I am using input type ="date".

1
  • Please provide some working or non working code samples so that we can help you out Commented Sep 22, 2016 at 10:10

1 Answer 1

0

You have the date as string hence you are getting the error you need to convert it to date object ,

$scope.dateField = new Date(date_string);

I would recommend to use a directive for this to use it in the input element.

<input convert-date type="date" ng-model="dateField">

app.directive('convertDate', function(){
return {
    restrict : 'A',
    scope : {ngModel : '='},
    link: function (scope) {
        if (scope.ngModel)
        {
         scope.ngModel = new Date(scope.ngModel);
        }
    }
}
});
Sign up to request clarification or add additional context in comments.

1 Comment

You are right ! Instead of using directive I used toString() to convert database date and It worked for me. Thank you !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.