tinyhamster tinyhamster - 6 months ago 21
AngularJS Question

angularJs date formatting on input field change

This is my input field for date:

<div class="input-group date">
<input type="text" class="form-control" id="datepicker" placeholder="dd/mm/yyyy" ng-model="abs.date">
</div>


value of this field is updated based on item selected in smart table. The problem is that what is displayed upon selecting an item is a timestamp and i need it to be in "dd/mm/yyyy" format. How do i apply a filter in this case without modifying the $scope value behind it?

Answer

You can do that by adding "| date:'dd/MM/yyyy'" to you binding. Like this:

<div class="input-group date">
            <input type="text" class="form-control" id="datepicker" placeholder="dd/mm/yyyy" ng-model="abs.date | date:'dd/MM/yyyy'">
        </div>
Comments