I found a solution based on this thread on stackoverflow https://stackoverflow.com/a/22658709/2012123
I filter the modelValue to my custom date format. So the viewValue will have the format 'dd.Mm.yy'.
ngModelCtrl.$formatters.push(function(modelValue) {
if(modelValue) {
var filtered = $filter('date')(modelValue, 'dd.MM.yy');
return filtered;
}
});
And with the following code I immediately transform my milliseconds to a valid date
/*https://stackoverflow.com/questions/22639485/angularjs-how-to-change-the-value-of-ngmodel-in-custom-directive*/
// $parse works out how to get the value.
// This returns a function that returns the result of your ng-model expression.
var modelGetter = $parse(attrs['ngModel']);
console.log(modelGetter(scope));
var timeInMilliseconds = modelGetter(scope);
if(timeInMilliseconds != null) {
// This returns a function that lets us set the value of the ng-model binding expression:
var modelSetter = modelGetter.assign;
// This is how you can use it to set the value 'bar' on the given scope.
modelSetter(scope, new Date(timeInMilliseconds));
console.log(modelGetter(scope));
}
I have updated the http://plnkr.co/edit/lZZh5VvCzH6yYh1t8xVM?p=preview accordingly. Now there are no more validation errors.