0

I have a simple ng-repeat that displays a list of names and icons:

<div ng-repeat="data in MyData">
    <p>Name: {{ data.Name }}</p>
    <span class="warning-sign"></span>
</div>

How can i modify this so that i display a list of all names, but icons only for the last 6 months?

I've tried:

$scope.Today= new Date();
$scope.SixMonths = new Date();
$scope.SixMonths .setDate($scope.SixMonths.getMonth() + 6);

Which i could incorporate an ng-show on my <span>

Oam Psy
  • 8,555
  • 32
  • 93
  • 157

1 Answers1

2

In your controller

var now = new Date();
$scope.sixMonthAgo = new Date().setMonth(now.getMonth() - 6);

In your template

<div ng-repeat="data in MyData">
    <p>Name: {{ data.Name }}</p>
    <span class="warning-sign" ng-if="data.checkingDate > sixMonthAgo"></span>
</div>
Ivan Burnaev
  • 2,690
  • 18
  • 27
  • Where has data.checkingDate come from?? – Oam Psy Aug 06 '14 at 16:16
  • In your case it doesn't realy matter. More information you can get from [another question](http://stackoverflow.com/questions/21869283/when-to-favor-ng-if-vs-ng-show-ng-hide). **data.checkingDate** is just a simple... You have some sort of collection (**MyData**), if you want to display icons only for last 6 month, you have to have some field in your object, which cares about date (creation date, registraion, etc.). In my example I called it `checkingDate`. – Ivan Burnaev Aug 06 '14 at 17:04