2014-05-09 252 views
1

我想打我的控制器之前解决一个承诺阵列things解决与角UI路由器一个承诺阵列

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; 
    }); 
    } 
}, 

什么我错在这里做什么?

回答

3

我想你需要:

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

因为没有这种外部收益内部回报率并不去任何地方。

现在resolve.things返回一个承诺,当解析时,将包含一个标题数组。


与其他一些调整:

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); 
    } 
} 
+0

我想,实际上,仍然没有骰子。 –

+0

我做了一些额外的调整。如果这不起作用,你能告诉我承诺的输出和'$ firebase(ref.child('things')。child(thingRef).child('title'))''的结果。 – Halcyon

+0

我被完全推迟了。我忘了注入'ref'。谢谢你的帮助! --- btw你确实需要'$ q.all()'' –