angular filters limitTo
HTML
<div ng-app = "fiddle">
<div ng-controller="MyCtrl">
<table class="table">
<input type="text" ng-model="fromDate" limit-to-date/> {{fromDate}}
</table>
</div>
</div>
JavaScript
var app = angular.module('fiddle', []);
app.controller('MyCtrl', ['$scope', function($scope){
$scope.fromDate = "01/01/1970 12:12";
}]);
/**
* limtToDate of date
* just show the HH:mm of the date
*/
app.directive('limitToDate', ['$filter', function ($filter) {
var dateFormat = "DD/MM/YYYY HH:mm"
return {
restrict: 'A',
link: function (scope, ielem, attrs) {
scope.$watch(attrs.ngModel, function (v) {
console.log('value changed, new value is: ' + v);
ielem.val($filter('limitTo')(ielem.val(), -5));
});
}
}
}]);