AngularJS loading progress bar

前端 未结 5 1206
甜味超标
甜味超标 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:48

    Since @Luc's anwser ngProgress changed a bit, and now you can only inject ngProgressFactory, that has to be used to create ngProgress instance. Also contrary to @Ketan Patil's answer you should only instantiate ngProgress once:

    angular.module('appRoutes', ['ngProgress']).run(function ($rootScope, ngProgressFactory) { 
    
        // first create instance when app starts
        $rootScope.progressbar = ngProgressFactory.createInstance();
    
        $rootScope.$on("$routeChangeStart", function () {
            $rootScope.progressbar.start();
        });
    
        $rootScope.$on("$routeChangeSuccess", function () {
            $rootScope.progressbar.complete();
        });
    });
    

提交回复
热议问题