我有一个简单的ng-repeat,显示名称和图标列表:
<div ng-repeat="data in MyData">
<p>Name: {{ data.Name }}</p>
<span class="warning-sign"></span>
</div>
我如何修改这个以便显示所有名称的列表,但仅显示过去6个月的图标?
我试过了:
$scope.Today= new Date();
$scope.SixMonths = new Date();
$scope.SixMonths .setDate($scope.SixMonths.getMonth() + 6);
我可以在ng-show
<span>
答案 0 :(得分:2)
在您的控制器中
var now = new Date();
$scope.sixMonthAgo = new Date().setMonth(now.getMonth() - 6);
在您的模板中
<div ng-repeat="data in MyData">
<p>Name: {{ data.Name }}</p>
<span class="warning-sign" ng-if="data.checkingDate > sixMonthAgo"></span>
</div>