Answers for "Angular watching for changes in $http.pendingRequests from directive"

0

Angular watching for changes in $http.pendingRequests from directive

scope.isBusy = function () {
    return $http.pendingRequests.length > 0;
};
scope.$watch(scope.isBusy, function (hasPending) {
    if (hasPending) {
      elm.show();
    } else {
      elm.hide();
    }
});

You may want to put this in a directive like this:

.directive('loadingBoxDir', ['$http', function ($http) {
    return {
       restrict: 'A',
       link: fn_link
    };
    function fn_link(scope, elm) {
       scope.isBusy= function () {
           return $http.pendingRequests.length > 0;
       };
       scope.$watch(scope.isBusy, function (hasPending) {
           if (hasPending) {
              elm.show();
           } else {
              elm.hide();
           }
       });
    }
}]);
Posted by: Guest on May-27-2020

Code answers related to "Angular watching for changes in $http.pendingRequests from directive"

Code answers related to "Javascript"

Browse Popular Code Answers by Language