I have an Angular collection related to a repeater that populates from MVC JsonResult.
$scope.loadData = function () { $http.get('/Product/GetDiscountCodes') .then(function (result) { console.log(result); $scope.discountCodes = result.data.DiscountCodes; $scope.selected = {}; }); };
One of the fields in the repeater is populated with a date. The date returned from the server is C # DateTime, which looks like this:
1/5/2015 12:02:00 AM
However, when it is bound to Angular, the following is displayed:
/ Date (1420434120000) /
How can I correctly display the date in a text box in the format mm / dd / yyyy?
I tried the ui-utils date format, but that didn't work.
I also tried to create my own directive that formats the date correctly, but when a save event occurs, the date is sent to the server-side method.
function inputDate() { return { require: 'ngModel', link: function (scope, element, attrs, ngModelController) { ngModelController.$parsers.push(function (data) { if (data === null) { return null; } var d = moment(data).format('YYYY-MM-DD'); return d; }); ngModelController.$formatters.push(function (data) { if (data === null) { return null; } return moment(data).format('MM/DD/YYYY'); }); } } } angular.module('discountApp') .directive('inputDate', inputDate);
Thanks for the help!
source share