Last active
September 25, 2017 09:03
-
-
Save tuanngominh/af0661b598c08135e2fdc13e7a1f39fc to your computer and use it in GitHub Desktop.
Get ordered children in order in clientside with 'once()'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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