I am trying to use a filter to filter out a date that is a string. The date I get from an API is
"/Date(1418716652000+0000)/"
I have a function which converts the date to the type I want:
1418716652000
The function is:
$scope.convertDate = function(published_first) {
var date = (published_first.match(/\(.*\)/, ''));
var convertedDate = date[0];
date = eval(convertedDate.replace(/\//g,''));
return date;
}
My HTML is:
<div id ="news" ng-repeat="new in news | filter:convertDate">
<h3 class="title" ng-repeat="n in new">
<span>{{n.title}}</span><br/>
<div class="title-data">
<span ng-if="n.byline.length > 0">by: {{n.byline}}</span>
<br/>
<span>
<span>published: {{n.published_first | date:'medium'}}</span><br/>
</span>
</div>
I've been trying to run this as a filter in my HTML in the ng-repeat div, but it's not working. I've also tried running the filter in the same span which includes the angular date:'medium' filter. That doesn't work either. Can someone help with what I'm missing?
+(convertedDate.replace(/\//g,''))or more semantically:Number(convertedDate.replace(/\//g,'')).convertedDate.replace(/\//g,'')?date = +published_first.match(/\d+/)[0].