I am trying do an asynchronous call in a loop, use the returned result and also make the variable 'q' available to the inner function.
How would I make q available to to the inner function (with the same value as it was before async call)?
var oController = this;
for (var q = 0; q < dataArray.length; q++) {
var InspectionNo = dataArray[q].inspectionNo;
//async call
oController._validateInspection(InspectionNo)
//returns flag
.then(function(flag) {
debugger;
if (flag) {
//q is not defined here
oController._doSomething(q)
}
});
}