Search code examples
angularjsdatefilterangularjs-ng-repeatangularjs-orderby

AngularJS orderBy date filter not working using Firebase


I'm using Firebase to store my data and I am aware that Firebase stores data as objects and not arrays. I have fixed that problem and have other filters working, but when I try to use "orderBy: 'date'" in my ng-repeat, it does not work. Here is the markup:

<div ng-repeat="event in events | limitTo:10 | filter:tfilter | orderBy: 'date'>
  <div class="row">
    <div class="col-md-6">
       <h4>{{event.date | amDateFormat:'MMMM Do'}}</h4>
    </div>
    <div class="col-md-6">
       <h4>{{event.name}}</h4>
    </div>
  </div>
 </div>

I've also tried using orderBy: 'event.date', but this did not work either. Anyone know the solution?


Solution

  • Figured it out -- super easy. In my mainSvc, I was returning objects instead of array. Where array is below was object.

    angular.module("zenCityApp")
    .factory("mainSvc", function ($rootScope, $log, $firebase) {
    
      var ref = new Firebase("https://zencity.firebaseio.com/events");
    
      var sync = $firebase(ref);
    
      var getEvents = function() {
        return sync.$asArray();
    
      };
    
      var addEvent = function (singleEvent) {
        ref.push(singleEvent);
      };
    
      return {
        getEvents: getEvents,
        addEvent: addEvent
      }
    
    });