AngularJS加载进度栏 [英] AngularJS loading progress bar

查看:88
本文介绍了AngularJS加载进度栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用AngularJS并使用$location.path('/path')进行重定向时,新页面的加载需要一段时间,尤其是在移动设备上.

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

是否可以添加进度条以进行加载?也许像YouTube这样的东西?

Is there a way to add a progress bar for loading? Maybe something like YouTube has?

推荐答案

对于YouTube一样的进度条,您可以查看 ngprogress .然后,例如,在配置完应用程序之后,您可以拦截路由事件.

For a progress bar as YouTube has, you can take a look at ngprogress. Then just after the configuration of your app (for example), you can intercept route's events.

并执行类似的操作:

app.run(function($rootScope, ngProgress) {
  $rootScope.$on('$routeChangeStart', function() {
    ngProgress.start();
  });

  $rootScope.$on('$routeChangeSuccess', function() {
    ngProgress.complete();
  });
  // Do the same with $routeChangeError
});

这篇关于AngularJS加载进度栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆