Question

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?

Was it helpful?

Solution

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);
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top