i'm attaching the date element in template as
<input type="date" ng-model="experience.date_start" date-ob>
The ng-model is binding value as a string to the date. For it i need to convert this string to object(new Date(experience.date_start)). I'm trying to achieve this context via directive called as date-ob
.directive('dateOb', function(){
return {
require: 'ngModel',
scope: {},
link: function(scope, element, attrs, ctrl) {
ctrl.$parsers.push(function(value) {
console.log('parser!', value);
return new Date(value);
});
ctrl.$formatters.push(function(value) {
console.log('formatter!', value);
return value;
});
}
}
});
It throws
Error: [ngModel:datefmt] Expected
2014-08-28to be a date http://errors.angularjs.org/1.4.5/ngModel/datefmt?p0=2014-08-28
How should be the code in date-ob directive for it? i'm newbie to .directive please give me the solution with explanation????..