I'm not sure why this isn't working so if anyone can help that would be great. I have nested functions and I wand to push the value returned by the firebase query and re use it in another firebase query, and then again, in a loop. Its essentially a poor man's infinite scroll. Nonetheless, I cannot get the value of the "arr" variable into the "numWanted" array outside so I can use it again in the next loop. What can I do to achieve the desired result?
Also, I have have beed trying to make the inner variables global, and push them out to another variable but that doesn't seem to work. Possible that I am just doing it wrong?
Thanks in advance..
$scope.loadMoreData = function() {
var numWanted = [];
console.log(numWanted);
firebase
.database()
.ref('products')
.orderByChild('rank')
.startAt(0)
.endAt(numWanted)
.limitToLast(3)
.once('value', function(products) {
products.forEach(function(product) {
var product = {
rank: product.val().rank
};
arr = product.rank;
});
numWanted.push(arr);
console.log(numWanted);
});
};
P.S. I realize this code doesn't actually work as you cannot use an array in a firebase query. My plan is to extract the number I need once the array has been populated.