Resolving a promise array
<p>I am having trouble in resolving a promise that is returned by firebase. This is an ionic - angularjs - firebase project that I am building to learn. The issue is that my function returns a promise that contains an array of 3 users but I am unable to unwrap this promise.</p>

<p><a href="https://i.stack.imgur.com/mUMAj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mUMAj.png" alt="Promise returned from firebase query"></a></p>

<p>My code:</p>

<pre><code>function eventusers(id) {
    var userarr = [];
    var deferred = $q.defer();

    // *The code below makes 2 firebase calls and returns an array of users*

    eventref.orderByChild("Eventid").equalTo(eventid).on("value", function(snap) {
        var users = snap.val();
        angular.forEach(users, function(value,key) {
            var obj = value;
            for (var prop in obj) {
                if(obj[prop] == "True") {
                    userref.child(prop).on("value", function (snap) {
                        var id = snap.val().email;
                        userarr.push(id);
                        console.log(userarr); // I am able to see the list of users here
                    });
                };
            }
        });
        deferred.resolve(userarr);
    });
    return deferred.promise;
};

//The console.log shows a promise (pls see the attached pic)
console.log(eventusers(eventid));

// I tried to loop through the response using angular.forEach and also a for loop but it does 
//not execute that part of the code as I do not see the response of the console.log. If I 
//replace the for loop with just console.log(response), then I get an empty array.

eventusers(eventid).then(function (response) {
    for (var i = 0; i &lt;response.length; i++) {
        console.log(response[i]);
    }
});
</code></pre>