[SOLVED] Change cursor to wait while the angular $apply is running


I have a complicated page with a lot of nested ng-repeat. The $apply function can take several seconds. During that time the browser is hung and the user cannot do anything.

As a courtesy I would like to change the mouse pointer to hourglass while $apply is running. How can I do that?


The trick is to change the cursor (using addClass), then invoke the slow code with a timeout at the end of which you change the cursor back to normal.


    var mybody = angular.element(document).find('body');
    mybody.addClass('waiting');   // set cursor to hourglass
    setTimeout(function() {
        mybody.removeClass('waiting');  // set cursor to normal
    }, 0);

You have to do the slow stuff in a timeout so that the addClass will be applied before the slow stuff starts.

The CSS is just

.waiting { cursor: wait; }

Answered By – John Henckel

Answer Checked By – Mildred Charles (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *