On the page I have <input type="text" />
to which user will enter date in format 31/12/2013
. This input field should be binded to $scope.startDate
field. But on $scope.startDate
I have to store date in following format "/Date(1385063675188)/"
(WCF REST service date format).
Question: How to make two way binding between html input and AngularJS model where date on both will be in different format (dd/MM/yyyy
and "/Date(1385063675188)/"
).
I'd use a directive for this. Like so:
directives.directive('dateConverter', ['$filter', function($filter) {
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModelController) {
ngModelController.$parsers.push(function(date) {
// Do to model conversion
});
ngModelController.$formatters.push(function(date) {
// Do to view conversion, possibly using $filter('date')
});
}
};
}]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With