0

HI, I am new to angular, I want to show data by past data from yesterday's date, and show data of today+future date.

//Here is the HTML code for Past Events
<div ng-repeat="event in events | filter:pastDate">
<p>{{event.name}}
<div>

//Here is the HTML code for Future Events
<div ng-repeat="event in events | filter:futureDate">
<p>{{event.name}}
<div>

Each event has a Start Date and End Date, Can anyone please explain how to achieve this.

Kranthi
  • 43
  • 1
  • 11

1 Answers1

0

Try this

var myApp = angular.module('app', []);
myApp.controller('TestController', ['$scope', function($scope) {
    var d = new Date();        
    d.setDate(d.getDate() - 1);
    $scope.events = [{date:new Date}, {date: new Date()},{date: d}];     
    prepareDate = function() {
      var date = new Date();
      date.setHours(0);
      date.setMinutes(0);
      date.setSeconds(0);
      return date;
    }  
    $scope.pastDate = function(actual){
      return actual.date < prepareDate();        
    }
    $scope.futureDate = function(actual){
      return actual.date >= prepareDate();        
    }
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="app">
  <div ng-controller="TestController">
    <h4>Past:</h4>
    <div ng-repeat='event in events | filter : pastDate'>{{event.date| date:'yyyy-MM-dd HH:mm:ss'}}</div>
    <h4>Future:</h4>
    <div ng-repeat='event in events | filter : futureDate'>{{event.date| date:'yyyy-MM-dd HH:mm:ss'}}</div>
</div>
</body>
Slava Utesinov
  • 13,410
  • 2
  • 19
  • 26