0

My issue is similar to the SO question below

Reverse order of items pulled from database in ng-repeat

HOWEVER, I am using the following method to bind all the transactions for a specific AccountID

var syncObject = $firebaseObject(fb.child("members/" + fbAuth.uid + "/accounts/" + $scope.AccountId));
syncObject.$bindTo($scope, "data");

The difference from the SO question mentioned above and mine is that I'm using the $firebaseObject to bind the data (three-way data binding).

So how can I show the list of transactions in reverse order? I want to show the most recent transaction at the top of the view

Thanks in advance for your help!

maninak
  • 2,633
  • 2
  • 18
  • 33
Luis Cabrera
  • 569
  • 1
  • 7
  • 18
  • 1
    Just some thoughts: since it's a *list* of transactions, maybe you should use `firebaseArray` instead of `firebaseObject`. Additionally, maybe [this](http://stackoverflow.com/questions/15266671/angular-ng-repeat-in-reverse) will be of use. –  May 11 '15 at 12:12
  • As described in the docs, $firebaseArray is for binding collections and $firebaseObject is not. You can get by without $bindTo. Just call $save() when you make changes and use the tools appropriately. – Kato May 11 '15 at 19:33

1 Answers1

3

You should be using $firebaseArray in this case as it'll allow you to sort however you want:

Javascript

var ref = fb.child("members/" + fbAuth.uid + "/accounts/" + $scope.AccountId);

$scope.data = $firebaseArray(ref);

HTML

<div data-ng-repeat="child in data | orderBy:'FIELD_TO_SORT_BY':true>
    <!-- other elements -->
</div>
maninak
  • 2,633
  • 2
  • 18
  • 33
Mathew Berg
  • 28,625
  • 11
  • 69
  • 90