1

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.

1 Answer 1

1

You have a conflict with your parameter named product and a local variable named product. You need to rename one of those.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.