0

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?

tinyhamster
  • 179
  • 1
  • 7

1 Answers1

0

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>
C. Molendijk
  • 2,614
  • 3
  • 26
  • 35
  • BTW this does the job but throws error because of the reason here https://docs.angularjs.org/error/ngModel/nonassign – Bettimms May 24 '16 at 11:30
  • If it throws that error, it can be 2 things. 1 there is no value or 2 it is not a date object in javascript. For the last one you then need to convert your value to a date. That fixes the error for my most of the times. – C. Molendijk May 24 '16 at 11:33
  • It throws the error for the reason mentioned in angularjs official page. None of your cases are valid. It has value, object is date and throws error. `ng-model` is simply holder of the value not for data manipulation. A better approach is to make a directive for that. A good example here http://stackoverflow.com/questions/14474555/how-to-format-a-date-using-ng-model – Bettimms May 25 '16 at 10:17