angularjs disable button on $http/$q calls

前端 未结 9 788
失恋的感觉
失恋的感觉 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:13

    You can use this in the run block. This will make sure all the buttons will be disabled whenever there is an active XHR call.

    myApp.run(function($rootScope, $http) {
        $http.defaults.transformRequest.push(function (data) {
            $rootScope.progress = true;
            return data;
        });
        $http.defaults.transformResponse.push(function(data){ 
            $rootScope.progress = false;
            return data;
        }) 
    });
    

    And then use the same model anywhere you want.

     
    

提交回复
热议问题