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?

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

BTW this does the job but throws error because of the reason here docs.angularjs.org/error/ngModel/nonassign
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.
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 stackoverflow.com/questions/14474555/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.