0

This is my Select and options should be in yyyy/MM/dd but they aren't

<select ng-model="date" ng-options="row.Triage_x0020_start_x0020_date as row.Triage_x0020_start_x0020_date for row in rows | jsonDate:'yyyy/MM/dd'| unique:'Triage_x0020_start_x0020_date'">

-- choose Topic --

This is my list which is displaying correctly row.Triage_x0020_start_x0020_date

<ul>
  <li ng-repeat="row in rows | filter:businessUnit | filter:topic | filter:date">
    <p>{{row.ID}}</p>
    <p>{{row.BusinessUnit}}</p>
    <p>{{row.Topic}}</p>
    <p>{{row.Triage_x0020_start_x0020_date | jsonDate:'yyyy/MM/dd'}}</p>
  </li>
</ul>

This is my list which is filter which converting json string to Date object.

var myApp = angular.module('myApp', ['ngRoute','ui.utils']);

myApp.filter('jsonDate', function ($filter) {
    return function (input, format) {
        return $filter('date')(new Date(input), format);
    };
});


myApp.controller('RowsListCtrl', function ($scope) {
    $scope.rows = myJSON;
});

Question is why filter doesn't work in select > options and displaying string 2014-04-02 18:00:00

2
  • You may want to look into a momentjs filter. Commented Sep 17, 2014 at 14:30
  • Still doesn't work.Also momentjs filter it's pretty the same as jsonDate. Commented Sep 17, 2014 at 14:51

1 Answer 1

2

you should convert date to timestamp in your filter

app.filter('jsonDate', ['$filter', function ($filter) {
  return function(input, format) {
    return $filter('date')(new Date(input).getTime(), format);
  };
}]);

But the date format 2014-04-02 18:00:00 won't work in Safari and Firefox when using new Date(), you can reference here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your help but that doesn't work either.It's still the same works fine in ul li but in options doesn't.

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.