I'm using firebase to save posts that have the following data:
createdAt: "Sun Apr 03 2016 18:32:46 GMT-0300 (BRT)"
What I'm trying to achieve is to get the most recent posts first and then load the older ones while the user scrolls down.
With posts retrieved using ngInfiniteScroll I'm being able to order desc using <div ng-repeat="post in posts | orderBy:'-createdAt'">
but ngInfiniteScroll keep returning the old posts first. I'm ordering but i'm ordering the older ones.
I already tried using the same logic ("-createdAt"
) in ngInfiniteScroll but it was not effective.
My js is pretty much this:
var baseRef = new Firebase(FBURL).child("posts");
var scrollRef = new Firebase.util.Scroll(baseRef, "createdAt");
$scope.posts = $firebaseArray(scrollRef);
$scope.posts.scroll = scrollRef.scroll;
Security and rules:
"posts": {
".read": true,
".indexOn": "createdAt",
"$post": {
".read": true,
".write": true,
"$other": {
".validate": true
}
}
}