1

I'm trying to resolve a promise array to things before hitting my controller:

resolve:{
  things: function($q){
    var promises = [];
    var titles = [];
    var thingRef = ['a1', 'a2', 'a3'];
    angular.forEach(thingRefs, function(thingRef){
      promises.push($firebase(ref.child('things').child(thingRef).child('title')).then(function(title){
        titles.push(title);
      }));
    });

    $q.all(promises).then(function(){
      return titles;
    });
  }
},

What am I doing wrong here?

1 Answer 1

3

I think you need:

return $q.all(promises).then(function(){
  return titles;
});

Because without that outer return the inner return doesn't go anywhere.

Now resolve.things returns a promise, that when resolved, will contain an Array of titles.


With some other adjustments:

resolve:{
  things: function($q){
    var promises = [];
    var thingRef = ['a1', 'a2', 'a3'];
    angular.forEach(thingRefs, function(thingRef){
      promises.push($firebase(ref.child('things').child(thingRef).child('title')));
    });

    return $q.all(promises);
  }
}
Sign up to request clarification or add additional context in comments.

3 Comments

I made some additional adjustments. If this doesn't work can you show me the output of the promise and the result of $firebase(ref.child('things').child(thingRef).child('title'))?
I was being completely retarded. I forgot to inject ref. Thanks for your help! --- btw you do need the return in front of $q.all()
Yes because $q.all produce a new promise that gets resolved when all the input promises are resolved. If you don't return anything you just get undefined.

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.