Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 <response.length; i++) {
- console.log(response[i]);
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement