I have a question about requests.I make first request then I suppose first onSuccess method will be runnning but program make second request immediately.How can i handle it? Context.getAlarmGroupById
is called 2 times immediately.
my code:
function loadAll () {
Context.getAlarmGroupChainById({
id: $stateParams.id
}, onSuccess, onError);
function onSuccess(data, headers) {
vm.temp=data;
var numberGroupChain=vm.temp.length;
for(var i=0; i<numberGroupChain; i++){
vm.location.push(vm.temp[i].location);
vm.alarmChainList.push({name: vm.location[i],active:null,totalAlarmGroupNumber:null});
//loadData(vm.temp[i].id);
asyncLoop(vm.temp[i].id);
}
}
function onError(error) {
AlertService.error(error.data.message);
}
var index = 0;
function asyncLoop(chainId) {
if(index >= vm.temp.length) {
return;
}
Context.getAlarmGroupById({
id:chainId
}, onSuccess, onError);
function onSuccess(data,headers){
index++;
asyncLoop();
}
function onError(data,headers){
index++;
asyncLoop();
}
}
}