I've a method like this in my ts file
getInitialBatches() {
var i = 0;
for (var dto of this.transferDTO.stockMovesDTOs) {
i++;
this.queryResourceService
.getBatchIdUsingGET(this.batchParams)
.subscribe((data) => {
this.allBatches[i] = data;
});
}
}
Since getBacthIdUsingGET
is a callback, It is not functioning the way I want.loop control variable i
gets increased by more than 1 by the time call back gets invoked so I'm not able to put values into every index of allBatches
array, Value is getting placed into random indexes. how to solve this issue?