0

Helo I used this loadingbar. I need the page to overlay when sending requests. But div for overlay is still visible after loading is ended. Here is my code:

    angular.module('app', ["angular-loading-bar"])
    .config(['cfpLoadingBarProvider', function (cfpLoadingBarProvider) {
        cfpLoadingBarProvider.parentSelector = '#loading-bar-container';
    }])
#loading-bar-container {
    pointer-events: all;
    z-index: 99999;
    border: none;
    margin: 0px;
    padding: 0px;
    width: 100%;
    height: 100%;
    top: 0px;
    left: 0px;
    cursor: wait;
    position: fixed;
    background-color: rgba(0, 0, 0, 0.6);
}

I need hide #loading-bar-container after loading is over. do you have any ideas how to do it? Thank you

12
  • Where are you using the loader bar? Commented Mar 4, 2018 at 8:37
  • this lib is so small that it's much easier for you to put breakpoint into "response" interceptor code there to check why setComplete() is not called. wild guess: you may have some background requests sent by some 3rd party component. wild guess #2: I'm not sure if loadingbar correctly behaves once request has been canceled(if cancelling does not trigged response interceptors - loadingbar will not disappear) Commented Mar 4, 2018 at 8:41
  • @G_S and why not? :) it's easy way to visualize some networking activity is running in background. Commented Mar 4, 2018 at 8:43
  • I didnt knew .config( code is used for interceptors Commented Mar 4, 2018 at 8:45
  • Thank you for your comments. If you think that problem is in loading bar component, which another component you would recommend me? Commented Mar 4, 2018 at 8:47

1 Answer 1

1

initially I misunderstood the question. So it's about hiding/showing container used for loading bar. Not about hiding/showing angular-loading-bar itself. So it could be done next way:

someModule.directive('loadingBarContainer', function ($rootScope) { 
    return { 
        restrict: 'A', 
        link: bindVisibilityToEvents 
    }; 

    function linkVisibilityToEvents($scope, $element) { 
        $rootScope.$on('cfpLoadingBar:loading', function () { 
            $element.show(); 
        });  
        $rootScope.$on('completed', function () { 
            $element.hide(); 
        }); 
    } 
}) 

And somewhere in your template:

<div id="loading-bar-container" loading-bar-container />

Also I believe it's more convenient to create different directive named say 'backdrop' and hide/show this element styled with

backdrop {
    pointer-events: none;
    cursor: wait; 
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

So blocking UI and visualizing HTTP activity would be less coupled.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.