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 Answer
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);
}
}
}
});
1 Comment
Ganesh Devkate
You are right ! Instead of using directive I used toString() to convert database date and It worked for me. Thank you !!