Francis Ducharme Francis Ducharme - 5 months ago 9
AngularJS Question

Formating date on the fly

I am receiving a value that I wish to strip of garbage, then pass to Angular's date format feature.

This is what I get:

/Date(1481328000000)/


I'd like
ng-repeat
to strip everything that's not the number, create a date from it then use:

<td>{{match.delivery_deadline_date | date: 'yyyy-MM-dd'}}</td>


In my
ng-repeat
directive. Is there anywhere I can specify to run a custom function that would strip the garbage before it tries to format it ?.

I've looked around and anything I googled ends up being about running code once
ng-repeat
is done, not running custom code on each rendered record.

Thanks.

Answer

You could always pass it a filter function. <td>{{match.delivery_deadline_date | dateFilter}}</td>

Then you would have a date filter function that sorts the date the way you want it.

angular.module('module.name')
  .filter('dateFilter', function () {
    return function (dateInputHere) {
       \\do some manipulation please
    }
  }
});
Comments