AngularJS loading progress bar

前端 未结 5 1209
甜味超标
甜味超标 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条回答
  •  梦毁少年i
    2020-12-30 10:59

    Here is a working solution which I am using in my application. ngProgress is the best library out there for showing load-bars when changing urls.

    Remember to inject the ngProgressFactory instead of ngProgress, as opposed to Luc's solution.

    angular.module('appRoutes', []).run(function ($rootScope, ngProgressFactory) {
        $rootScope.$on("$routeChangeStart", function () {
            $rootScope.progressbar = ngProgressFactory.createInstance();
            $rootScope.progressbar.start();
    
        });
    
        $rootScope.$on("$routeChangeSuccess", function () {
            $rootScope.progressbar.complete();
        });
    });
    

    Update Nov-2015 - After analyzing this approach with chrome timings, I have observed that this would not be the correct way for adding a loading bar. Sure, the loading bar will be visible to visitors,but it will not be in sync with actual page load timings.

提交回复
热议问题