Angularjs tab Loading spinner while rendering

前端 未结 5 1926
别跟我提以往
别跟我提以往 2021-02-05 10:51

I have a page with some tabs and each tab has large amount of angularjs bindings.This is sample page where i am facing issue.Each tabs take about 10 seconds to render.

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-05 11:14

    You can change your code like this:

    $timeout(function() {
      $scope.currentTab = tab.url 
    }, 100);
    

    Demo: http://jsfiddle.net/eRGT8/1053/

    What I do is, I push currentTab change to next digest cycle. (It's some kind of a hack, not a solution I proud of.) Therefore, in first digest cycle (before $timeout invoked) only loading is shown. In the next digest cycle, the blocking ng-repeat stuff starts working but since we make loading visible previously, it appears.

    :)

    This solves your problem, but running long running and blocking javascript that hangs browser completely is not a good user experience. Also, since browser is hang completely, the loading gif will not animate, only will be visible.

提交回复
热议问题