Posts

Showing posts with the label Ng Controller

AngularJS - Convert Dates In Controller

Answer : item.date = $filter('date')(item.date, "dd/MM/yyyy"); // for conversion to string http://docs.angularjs.org/api/ng.filter:date But if you are using HTML5 type="date" then the ISO format yyyy-MM-dd MUST be used. item.dateAsString = $filter('date')(item.date, "yyyy-MM-dd"); // for type="date" binding <input type="date" ng-model="item.dateAsString" value="{{ item.dateAsString }}" pattern="dd/MM/YYYY"/> http://www.w3.org/TR/html-markup/input.date.html NOTE: use of pattern="" with type="date" looks non-standard, but it appears to work in the expected way in Chrome 31. create a filter.js and you can make this as reusable angular.module('yourmodule').filter('date', function($filter) { return function(input) { if(input == null){ return ""; } var _date = $filter('date')(new Date(input), ...