How to Disable or Stop Angular BlockUI on particular request

Oswaldo Alvarez picture Oswaldo Alvarez · Jul 8, 2015 · Viewed 7.7k times · Source

I have turned on automaticly BlockUI show on any request, but i need to turn off on a particular request. I need something like this.

$scope.getTags = function ($query) {
            blockUI.notShow();
            return blogService.getTags($query)
        };

Answer

Oswaldo Alvarez picture Oswaldo Alvarez · Jul 8, 2015

I try something and work.

1) Stop Autoblock

app.config(["$routeProvider", "blockUIConfig", function ($routeProvider, blockUIConfig) {
    blockUIConfig.autoBlock = false;
}]);

2) Create an Interceptor

app.config(["$httpProvider", function ($httpProvider) {
    $httpProvider.interceptors.push('myInterceptorService');
}]);
app.factory('myInterceptorService', ['$q', '$injector','blockUI',
    function ($q, $injector, blockUI) {

        var myInterceptorServiceFactory = {};

        myInterceptorServiceFactory.request = function (config) {
            if (blockUI.noOpen == null) {
            blockUI.stop();
        } else {
            blockUI.noOpen = null;
        }
            return config;
        }
        myInterceptorServiceFactory.responseError = function (rejection) {
            return $q.reject(rejection);
        }
        myInterceptorServiceFactory.response = function (response) {
            if (blockUI.noOpen == null) {
            blockUI.stop();
        } else {
            blockUI.noOpen = null;
        }
            return response || $q.when(response);
        }

        return myInterceptorServiceFactory;
    }
]);

3) Alert in Controller

$scope.getTags = function ($query) {
            blockUI.noOpen = true;
            return blogService.getTags($query)
        };