Within my Angular application, there is a snippet of code that looks 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)
}
}
}
This piece of code contains a simple for loop with an Angular service call to the backend API inside it.
The array has only one item. As a result, the value of i
should always be 0
. However, the console.log(i)
statement before the service call prints out 0
, while the one after the service call prints 1
. Can anyone identify what might be causing this behavior?