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
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;
}
});
}
};
};