NG-Repeat compare to current date using filter?

angularjs, angularjs-ng-repeat, javascript

Solution

Here is an example of how I used a filter to only show orders from the last two days

.filter('getOrders', function() {
  return function (orders) {

    var filtered_list = [];

    for (var i = 0; i < orders.length; i++) {

      var two_days_ago = new Date().getTime() - 2*24*60*60*1000;
      var last_modified = new Date(orders[i].last_modified).getTime();

      if (two_days_ago <= last_modified) {
        filtered_list.push(orders[i]);
      }
    }
    return filtered_list;
  }
});

DOM looks like this

<tr ng-repeat="order in orders|getOrders">

Hopefully this fiddle helps JSFiddle

Problem

Ok I have an object that contains a list of dates and I'm traversing it like so: ``` <select ng-click="monthpicker()" > <option class="animate-repeat" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="{{returnpicker.date}}">{{returnpicker.date | date:'yyyy-MMM' }}</option> </select> ``` using ng-repeat this returns the following: ``` <select ng-click="monthpicker()"> <!-- ngRepeat: returnpicker in monthpicker(alldatesdump) --> <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option> <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option> <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option> <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option> <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option> <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option> <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option> <option class="animate-repeat ng-scope ng-binding" ng-repeat="returnpicker in monthpicker(alldatesdump)" value="2013-Nov">2013-Nov</option> ``` and so on for each month in the object now this is because it's returning a month name and a year for each day in the object. Ok so i have two questions: 1: How do i filter the results so they only return one example of each month name and the year? 2: how do i set it so it returns only from the current month? I'd like to achive this using AngularJS filters only but i do have jquery avail if needed! ********UPDATE************** heres the current scope item in my JS file: ``` scope.monthpicker = function(alldatesdump){ var alldatesdump = booking.getalldates(); /*for (var date in alldatesdump){ if (alldatesdump.hasOwnProperty(date)){ console.log(date); } } for (var date in alldatesdump) { var obj = alldatesdump[date]; for (var prop in obj) { // important check that this is objects own property // not from prototype prop inherited if(obj.hasOwnProperty(prop)){ console.log(prop + " = " + obj[prop]); } } }*/ return alldatesdump; }; ```

Original source