如何将今天的日期与角度ng-repeat

时间:2016-12-13 09:20:47

标签: javascript angularjs

<li ng-repeat="iteration over values" ng-show="compare date with today's date">
//code for display
</li>

如何将日期与今天的日期进行比较?

3 个答案:

答案 0 :(得分:1)

HTML:

<li ng-repeat="iteration over values" ng-if="compareDate(iteration)">
  //code for display
</li>

JavaScript的:

$scope.compareDate = function (val) {
  // your code here
  return true or false
}

答案 1 :(得分:1)

 <li ng-repeat="iteration over values" ng-show="showEvents(dt,today )">
    //code for display
    </li>

$scope.showEvents=function(dt,today){
      var datea = moment(dt);
      var dateb = moment(today);
      return datea.diff(dateb, 'days') >= 0;
    }

答案 2 :(得分:1)

如果您想使用momentjs,那么Nikita的答案就可以了。

如果你想在核心js中进行比较,那么: -

<li ng-repeat="iteration over values" ng-show="dateCompare(dt)">
    //code for display
 </li>

$scope.dateCompare = function(dt){
      var otherdate = new Date(dt);
      var today = new Date();
      return otherdate.getFullYear() === today.getFullYear() && otherdate.getMonth() === today.getMonth() && otherdate.getDate() === today.getDate();
}