Reputation: 1631
I'm new to angular and firebase and I want to order my fetched list of contestants dynamically (3-way-binding).
app: https://shining-torch-1269.firebaseapp.com/#/ see it's not ordered!
code of the service for getting the data from firebase:
app.service('ContestantsService', function ($firebaseArray, FIREBASE_URI) {
var service = this;
var ref = new Firebase(FIREBASE_URI);
var contestants = $firebaseArray(ref);
service.getContestants = function () {
return contestants;
};
service.addContestant = function (contestant) {
contestants.$add(contestant);
};
service.updateContestant = function (contestant) {
contestants.$save(contestant);
};
service.removeContestant = function (contestant) {
contestants.$remove(contestant);
};
});
I have tried already the method var contestants = $firebaseArray(ref).orderBy('score')
Upvotes: 1
Views: 277
Reputation: 1631
I get the solution.. here's the solution in code
I basically some parts and here a 4 step solution for the problem.
var query = ref.orderByChild('score').limitToLast(10); // added this one
var contestants = $firebaseArray(query);
{
"rules": {
".read": true,
".write": true,
".indexOn":"score",
"score": {
".indexOn": ".value"
}
}
}
app.filter('reverse', function() {
return function(items) {
return items.slice().reverse();
};
});
<tr ng-repeat="contestant in main.contestants | reverse ">
Upvotes: 3