Angular ng-show日期是否在时间内?

时间:2016-02-18 03:57:21

标签: javascript angularjs json font-awesome

所以我有一个按钮,点击后会显示一个数据列表。如果JSON键值存在,我在那里添加一个字体真棒字体。但这是问题所在。关键是约会。我需要我的ng-show来检查这个日期是否在今天的30天之内。我的按钮代码是:

                <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> 

JSON中的对象数组是:

"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."
}
],

如何正确实现这一目标?试过使用&#39; .length&lt; =&#39;事情的类型,但没有运气。

非常感谢。

1 个答案:

答案 0 :(得分:0)

您应该在控制器中使用一个函数(假设控制器为ppt):

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

然后:

<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>