2017-09-15 8 views
0

これは実装上の問題です。 私は何が間違っているのか分かりません。

var promises = items.map(function(item) { 
     return HttpWrapper.send(url, {"operation": 'GET'}).then(function(pricingOptions) { 
      item.selectedItem = pricingOptions[0]; 
      item.selectedItem.zone = 'us-east-1a'; 
      arr.push(item); 
     });  
}); 
$q.all(promises).then(function(result) { 
    vm.selectedItems.server = arr; 

しかし、問題がある...

それは最初に解決しに来...

item.selectedItem = pricingOptions[0]; 
item.selectedItem.zone = 'us-east-1a'; 

それは$q.all右の内側にくるべきか?または、$q.all()を完全に削除することはできますか?

私は間違っていますか?

+2

なぜマップ関数の後に 'else'ステートメントがありますか?また、HttpWrapperはどのように見えますか? –

+0

@LenilsondeCastro elseは不要で、HttpWrapperは$ httpとみなすことができます – StrugglingCoder

+0

allPromiseに '$ q.all(約束).then(function(result){...} 'のようなエラーコールバックを追加することを検討してください。 ); 'あなたの約束の一つが解決されないかもしれないからです。 –

答えて

0
var promises = items.map(function(item) { 
     return HttpWrapper.send(url, {"operation": 'GET'}).then(function(pricingOptions) { 
      item.selectedItem = pricingOptions[0]; 
      item.selectedItem.zone = 'us-east-1a'; 
      return item; 
     });  
}); 
$q.all(promises).then(function(result) { 
    vm.selectedItems.server = result;