Error Using "limitToLast" on friebase object


#1

var fbData = new Firebase(‘https://FIREBASE_URL/’);

fbData.limitToLast(10).once(“value”, function(snapshot) {
var i = 0;
var postSnapshot = snapshot.child(“posts”);
snapshot.forEach(function(childSnapshot) {
console.log(‘user %s is in position %d with %d points’, snapshot.key(), i++, snapshot.val());
var childData = childSnapshot.val();
});
});


#2

You are trying to perform a query directly onto a firebase object, you need to create a query first https://www.firebase.com/docs/web/api/query/limittolast.html

var ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs");
ref.orderByChild("weight").limitToLast(2).on("child_added", function(snapshot) {
  console.log(snapshot.key());
});

Also take a look at AngularFire (https://www.firebase.com/docs/web/libraries/angular/api.html) it will perform most of the abstraction you’ll need and is more suited towards Angular/Ionic applications.


#3

it working now, with this:

fbData.once(“value”, function(snapshot) {
var i = 0;
var postSnapshot = snapshot.child(“posts”);
postSnapshot.forEach(function(childSnapshot){
console.log(‘user %s is in position %d’, childSnapshot.key(), i++);
var childData = childSnapshot.val();
console.log(childData);
});
});
};

still reading on the limit to last!!!
thanks for the AngularFire reference.