AngularJS loading progress bar

前端 未结 5 1182
甜味超标
甜味超标 2020-12-30 10:26

When using AngularJS and doing a redirect using $location.path(\'/path\') the new page takes a while to load, especially on mobile.

Is there a way to ad

5条回答
  •  一生所求
    2020-12-30 10:49

    if it is the next route that takes time to load e.g. making ajax call before the controller is run (resolve config on route) then make use of $route service's $routeChangeStart, $routeChangeSuccess and $routeChangeError events.

    register a top level controller (outside ng-view) that listens to these events and manages a boolean variable in its $scope.

    use this variable with ng-show to overlay a "loading, please wait" div.

    if the next route loads fast (i.e. its controller runs quickly) but data that are requested by the controller take a long to load then, i'm afraid, you have to manage the visibility state of spinners in your controller and view.

    something like:

    $scope.data = null;
    $http.get("/whatever").success(function(data) {
        $scope.data = data;
    });
    
    
    ...

提交回复
热议问题