In my angular application, I have a piece of code like this
for (var i = 0; i < $scope.itemList.length; i++) {
if ($scope.itemList[i].serialNumber == quickCode) {
console.log(i)
returnsService.getNoReceiptErrorMessages($scope.itemList[i].sku, quickCode).then(function (response) {
console.log(i)
}
}
}
Its just a for loop and in side the loop there is an angular service to call backend api.
The array have just one item only. So the value of i is expected to be 0 all the time. But the console.log(i) before the service call print 0 and after service call prints 1. Can some one point out what is happening here.