Search code examples
angularjsng-options

Use filter on ng-options label - NOT WORKING


I am trying to format a time value from a collection I am using for time within ng-options.

The format in the db is 00:00:00 but I want to present 00:00 AM/PM to the user.

I am trying this;

ng-options="time.time as (time.time | date:'h:mma') for time in times"

With no luck. Seems like it should be pretty straight forward. shortTime does not work either.

Thanks.


Solution

  • Basically your date should return in correct format so that it would be recognized as date by the date filter

    2015-11-05 06:00:00 should be changed to 2015-11-05T06:00:00

    $scope.times = [
        {time: '2015-11-05T01:00:00', id: '1'},
        {time: '2015-11-05T02:00:00', id: '2'},
        {time: '2015-11-05T03:00:00', id: '3'},
        {time: '2015-11-05T13:00:00', id: '4'},
    ];
    

    Demo Here