6

How to turn off or stop Angular BlockUI on special request

 2 years ago
source link: https://www.codesd.com/item/how-to-turn-off-or-stop-angular-blockui-on-special-request.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to turn off or stop Angular BlockUI on special request

advertisements

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


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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK