I have a datepicker within a form. I would like to set one format for the view but apply a different format to the model value (which is sent to an API). In simple terms I want the user to see 'dd/mm/yyyy' but need the date to be sent in ISO format.
This is my directive:
app.directive('standardDatepicker', function($timeout) {
return{
restrict: 'A',
require : '^ngModel',
link: function(scope, element, attrs, ngModel, ngModelCtrl){
element.datepicker({
format: "dd/mm/yyyy",
autoclose: true,
}).on('changeDate', function(e) {
ngModel.$viewValue = e.date;
ngModel.$render();
});
}
}
});
Is there an easy way to achieve this?