Use counter for ajax loader I was using a Boolean var for indication of loading so my code looked like this:
(this example is in angularjs but i think it can be relevant for any ajax call handlers)

//HTML:
&lt;div ng-show="$scope.isLoading"&gt;...LOADING...&lt;/div&gt;

//JS:
//Init
$scope.isLoading = false;

//Executing http request:
$scope.isLoading = true;
mainService.post(alteredItems).then(function (response) {
init();
}).catch(function (err) {
  $scope.callBack(err);
}).finally(function () {
  $scope.isLoading = false;
});

function init() {
  $scope.isLoading = true; //another loading        
  mainService.get().then(function (response) {
  if (response) {

  }
  $scope.isLoading = false;
  });
}


The problem I had was that if 1 ajax method will complete before the other one so the "isLoading" will be false, and the loader will not be displayed although the request has not yet ended.

I converted the $scope.isLoading to int. So now code looks like this:

//Init
$scope.isLoading = 0;

//Start any ajax call
$scope.isLoading++;

//Finish
$scope.isLoading--;


Which works great, also no need to change the html because of the casting.
I can't find a drawback in this approach and it seems better than the Boolean option.

What do you think?
You SHOULD consider migrating to Angular (aka Angular2, aka Angular5) from ANgularJS (version 1), as it's not developing and soon won't be supported anymore. 
I guess nested promises would be much useful here (more details below).


Rewrite init() as follow

function init() {
  return mainService.get().then(function (response) {
    if (response) {

    }
    $scope.isLoading = false;
  });
}


And in main block instead of

mainService.post(alteredItems).then(function (response) {
  init();
})


Write:

mainService.post(alteredItems).then(function (response) {
  return init();
})


In this case your finally would be called AFTER bot async calls completed.

P.S. Consider using library cg-buisy https://github.com/cgross/angular-busy
It automates displaying of loading indicator and accepts promises. Used it a lot in production.