angularjs disable button on $http/$q calls

前端 未结 9 767
失恋的感觉
失恋的感觉 2021-02-03 10:12

following the DRY principal, i want to write a button directive which keeps button disabled for the duration of $http class.

I want to do this so as to forbid user from

9条回答
  •  执笔经年
    2021-02-03 11:12

    You can create a directive that could be used on the element you want disabled.

     var loadingDisabled = function ($http) {
        return {
          restrict: "a",
          link: function (scope, elem, attr) {
                    scope.isLoading = function () {
                        return $http.pendingRequests.length > 0;
                    }
                    scope.$watch(scope.isLoading, function(v) {
                        if (v) {
                            elem.disabled = true;
                        } else {
                            elem.disabled = false;
                        }
                    });
    
                }
    
        };
      };
    

提交回复
热议问题