1

I'm trying to get some data from an Object that has been retrieved from Firebase using AngularJS.

The object looks like this ("feed_items" in code):

enter image description here

And the first 10 Objects look like:

enter image description here

So I'm trying to do a loop as follows:

function getUniqueFilters(feed_items) {    

    angular.forEach(feed_items, function(value, key){                  
        console.log(value);      
    });
}

The output of that console.log(value) is:

enter image description here

I don't understand why I'm not getting any of the first 10 Objects, which are the ones I'm needing the data from. How do I get those?

Thanks in advance!

4
  • 1
    Are you sure the value of each object is not a function? Output your keys and make sure you're getting back what you want or try value() to see if the functions are returning the value you're looking for. Commented Jan 30, 2014 at 10:24
  • Hi @pedalpete, I've updated my post to show how the Objects look like. They are definitely not a function. Commented Jan 30, 2014 at 10:50
  • That's interesting Teknotica. This should't matter, but for consistency, I remcommend you output function(key, value) rather than (value, key), as that is more consistent with the data structure. Having said that, have you output the content of key to see what that is returning? How about just passing (i){console.log(i) as the callback for forEach and see what that gives you. I often find these small changes will give you hints to what is happening. Commented Jan 30, 2014 at 21:55
  • Hi @pedalpete thanks for your response. I found the issue: data is still not available at that point. Thank you anyways! Commented Jan 31, 2014 at 10:00

2 Answers 2

1

My guess is by the time you use console.log, the request is still not resolved.

Probably firebase populates the object after it gets the data from the server.

console.log is by reference and asynchronous so you still see the data in the console.

I'm not familiar with firebase but you should probably look for a callback / promise.

For testing I recommend halting the execution like so:

console.log(object); 

debugger; // now check inside your console
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. You are right, when adding the debugger I can see the data is still not there. I'll try to get a callback then. Thanks for your help!
0

what if you try to do so:

function getUniqueFilters(feed_items) {    

    for(var i=0; i<10; i++){
       console.log(feed_items[i]);      
    }
}

1 Comment

Thanks @STEVER - read below as that's what is apparently the issue.

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.