在 AngularJS 中更改路由(动画、加载程序等)时触发回调 [英] Fire a callback when route is changed (animations, loaders etc) in AngularJS

查看:21
本文介绍了在 AngularJS 中更改路由(动画、加载程序等)时触发回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 AngularJS 的新手.

当路由改变时,ng-view改变内容.我希望能够做的是在路线改变时挂钩一些行为.

  1. 例如,我希望能够为我们的视图设置动画离开(淡出,向左滑动)和下一个视图时随时可用,淡入淡出并将视图滑入.这可以通过在路由加载时向正文添加一个类,并在路由更改成功时删除一个类来实现

  1. I would like to be able to for example animate the view we're leaving (fading out, and sliding to the left) and when the next view is readily available, fade and slide the view in. This could be implemented by adding a class to body on route loading, and removing a class on route change successfull

我希望能够将视图堆叠在右侧当前视图,以便当向前移动时,下一个视图是首先加载到当前视图的右侧,然后视口向右滑动,因此当前视图几乎滑出视图,然后下一个滑入视图(Windows 手机就像画布导航一样)

I would like the ability to have the views stacked on to the right of the current view, so that when one moves forward, the next view is first loaded to the right of the current one, then the viewport slides to the right so the current view slides almost out of view, and the next one slides into view (windows phone like off canvas navigation)

$routeProvider 是否适合执行此操作?

Is the $routeProvider the right place to do this?

有没有大师可以为我指明正确的方向?

Are there any gurus out there that could point me in the right direction?

推荐答案

经过更多研究,为此目的触发了一些事件.

After some more research, there are events fired for this purpose.

$scope.$on('$routeChangeStart', function(scope, next, current){
   //...
});

$scope.$on('$routeChangeSuccess', function(scope, next, current){
   //...
});

如果问题是对某些内容进行动画处理(例如路线更改),我建议使用 ngAnimate.在此处

If ones problem is to animate something (for example on route change) I recommend using ngAnimate. Read more about it here

这篇关于在 AngularJS 中更改路由(动画、加载程序等)时触发回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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