0

So I have a button that when clicked displays a list of data. I am adding a font awesome font in there if the JSON key value exists. But here is the problem. The key is a date. I need my ng-show to check if this date is within 30 days of todays date. My code for button is:

                <button class="naviaBtn naviaBlue" ng-click="alertShow = (alertShow == 4 ? -1 : 4)"><i class="fa fa-exclamation-circle fa-2x" ng-show="ppt.Dates.key == todaysDate"></i>recent denials</button> 

The object array in JSON is:

"Dates": [
{
  "key": "2/25/2016",
  "value": "The last day to add or edit your March GoNavia Commuter Benefits order."
},
{
  "key": "3/31/2016",
  "value": "The last day to submit claims for your 2015 Health Care FSA."
},
{
  "key": "3/31/2016",
  "value": "The last day to submit claims for your 2015 Day Care FSA."
}
],

How can I achieve this correctly? Have tried with using '.length <=' type of thing, but no luck.

Thanks much.

Mark
  • 1,812
  • 3
  • 29
  • 51
  • 1
    You're going to have to find a way to compare dates as an expression in the ng-show. Here's a start, the trick is getting the formatting right: http://stackoverflow.com/questions/492994/compare-two-dates-with-javascript – Kevin Hernandez Feb 18 '16 at 04:02

1 Answers1

0

You should use a function in your controller (assuming controller as ppt):

this.checkDate = function (dateString) {
    var daysAgo = new Date();
    daysAgo.setDate(daysAgo.getDate() - 30);
    return (new Date(dateString) > daysAgo);
}

And then:

<button class="naviaBtn naviaBlue" ng-click="alertShow = (alertShow == 4 ? -1 : 4)"><i class="fa fa-exclamation-circle fa-2x" ng-show="ppt.checkDate(ppt.Dates[index].key)"></i>recent denials</button> 
Simon K
  • 2,762
  • 1
  • 11
  • 20