$ q.all AngularJS中的invokation问题

时间:2021-06-07 00:19:51

It is more of an implementation issue. I am not sure what have I done wrong.

这更像是一个实施问题。我不确定我做错了什么。

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;

But the problem is ...

但问题是......

it resolves first and comes to ...

它先解决然后来......

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

It should be coming inside $q.all right? Or can I remove $q.all() altogether.

它应该进入$ q.all吧?或者我可以完全删除$ q.all()。

What am I doing wrong?

我究竟做错了什么?

1 个解决方案

#1


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;

#1


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;