Just starting out with Ionic + Firebase and need help. After getting length of array, I want to display its number. Basically trying to get box on screen that constantly shows how many current people are in specific chat room as people move in and out.
Got code below from AngularFire documentation which I can get to log number to console, but doesn't continuously update or allow to use value of length outside of function.
// Find and log total number of users in this reference
var countUsersRef = $firebaseArray(ref);
countUsersRef.$loaded().then(function(arr) {
console.log("Users in room = " + arr.length);
});
$loaded()
only fires once, when the initial data has loaded.
You're looking to extend the $firebaseArray
. You'll want to hook into $$added
and $$removed
.
Note that these are considered advanced topics. If you're just beginning, you might want to consider simply not displaying the user count.