Having trouble extracting the value from a Firebase query in my factory to the controller. Any suggestions or ideas would be greatly appreciated!
Controller:
main.controller("mainCtrl", function($scope, totalusers){
$scope.city = "whatever";
$scope.total = totalusers.getusers($scope.city);
});
Factory (contains the query to retrieve the number of users with the specified Name):
app.factory("totalusers", function(FURL) {
var gettotalusers = {};
gettotalusers.getusers = function(city) {
var tusers = new Firebase(FURL + "/Users/" + city);
var count = 0;
tusers.on("value", function(snapshot) {
snapshot.forEach(function(child) {
if (child.val().Name != undefined) {
count++;
}
});
var total = count;
return total;
});
}
return gettotalusers;
});
If you have any insights or suggestions, feel free to share. Thanks in advance! ;)