I'm fetching a list of products however it does't have the qty values in the response I get back from the first HTTP
call therefore I have to make another call to get the qty values of the returned products from the first call.
First HTTP call: --
vm.search = function() {
itemService.newSearchProducts(searchData)
.then(function (response) {
for (var i = 0; i < response.data.Results.length; i++) {
vm.getItemStock(response.data.Results[i].product_idField);
}
vm.prodData = response.data.Results;
})
}
Second HTTP call: This call requires the item Id from above to get the right data for specific product.
vm.getItemStock = function (ids) {
var getstock = {
SessionId: orderService.baseObj().SessionId,
ProductIds: [ids]
}
itemService.itemStock(getstock)
.then(function (response) {
vm.stockQty = response.data.Results[0].qtyField;
})
}
Second call response, this is the response looks like after success call so this only should show on the table row/column of this item.
<table class="table table-bordered" style="margin-bottom: 0; border: none;">
<thead>
<tr>
<th>Sku</th>
<th>Product Name</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="res in vm.prodData">
<td width="20%">{{res.firstCall}}</td>
<td><a href="#!/item/{{ res.firstCall }}" class="itemName">{{res.nameField}}</a> </td>
<td>{{ SecondCall }}</td>
<!--<td><button class="btn btn-success" style="display: block; margin: 0 auto;">Add to basket</button></td>-->
</tr>
</tbody>
</table>
How can I render the correct data from the second call to be inline with the first call.
Fixed using the answer below
$q.all(qty).then(function (result) {
for (var i = 0; i < result.length; i++) {
quantity.push(result[i].data.Results[0].qtyField);
}
for (var j = 0; j < vm.prodData.length; ++j) vm.prodData[j].qtyField = quantity[j];
});