Skip to content

Instantly share code, notes, and snippets.

@tuanngominh
Last active September 25, 2017 09:03
Show Gist options
  • Save tuanngominh/af0661b598c08135e2fdc13e7a1f39fc to your computer and use it in GitHub Desktop.
Save tuanngominh/af0661b598c08135e2fdc13e7a1f39fc to your computer and use it in GitHub Desktop.
Get ordered children in order in clientside with 'once()'
// WORKS
// firebase API - with once('value')
firebase().database().ref('/dinosaurs').orderByChild('height').once('value', function (snapshot) {
snapshot.forEach(function(child) {
console.log(child.val())
});
});
// firebase API - with once('child_added')
firebase().database().ref('/dinosaurs').orderByChild('height').once('child_added', function (snapshot) {
console.log(snapshot.val());
})
// angularfire2's 4.0.0-rc.1 API
db.list('/dinosaurs', {
query: {
orderByChild: 'height'
}
})
.subscribe((snapshot) => {
console.log(snapshot);
})
// DOESN'T WORK
firebase().database().ref('/dinosaurs').orderByChild('height').once('value', function (snapshot) {
console.log(snapshot.val());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment