Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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();
           }
       });
    }
}]);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript random point on unit sphere 
Javascript :: how to calculate each row with on change table <td<input jquery 
Javascript :: Compare unequality of two operands. 
Javascript :: set ibm cloud node environment variables 
Javascript :: shaynlink 
Javascript :: code in nested forEach loop- react native 
Javascript :: react addon update 
Javascript :: jquery on load vs ready 
Javascript :: document ready function is undefined 
Javascript :: smaler div on devices 
Javascript :: parsley validation checkbox alignment 
Javascript :: contact form7 404 wp-json feedback 
Javascript :: set up chrome dev tools adonisjs 
Javascript :: what does results.push({}) nodejs mean 
Javascript :: vue change input value from console 
Javascript :: how to make sticky footer with react router 
Javascript :: handling event changes 
Javascript :: how to change the model object django in javascript 
Javascript :: rename object keys using regexp 
Javascript :: install phantomjs Alpine Linux 
Javascript :: node-emoji list 
Javascript :: most popular company with nodejs 
Javascript :: defoult function atributes 
Javascript :: javascript random six digit number with animation 
Javascript :: es6 1 to one 
Javascript :: Beginning Node.js 
Javascript :: is nodejs code visible client side 
Javascript :: array con tridimensional javascript 
Javascript :: Ivy J. Livingston 
Javascript :: insert html block and dynamic content 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =