When the onInit function is called, an API request is made.
vm.$onInit = function() {
var callInProgress = false;
var resultsLoaded = false;
var url = '/api/times/cst';
if(callInProgress === false && resultsLoaded ===false){
callInProgress = true;
HttpWrapper.send(url,{"operation":'GET'}).then(function(result){
vm.times = result;
resultsLoaded = true;
},function(error){
vm.errorInApi = true;
});
}
The issue arises from $onInit being called multiple times, causing the flags callInProgress and resultsLoaded to be re-initialized each time.
This repeated check is not effective in preventing multiple API calls when $onInit is triggered.
Despite this problem, the API continues to be called every time $onInit runs during initialization.
How can I ensure that the call is only made once? It must still occur within $onInit.