Francis Ducharme Francis Ducharme - 1 year ago 75
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:


I'd like
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
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
is done, not running custom code on each rendered record.


Answer Source

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.

  .filter('dateFilter', function () {
    return function (dateInputHere) {
       \\do some manipulation please
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download