$locationChangeStart、$routeChangeStart 和 $stateChangeStart 之间的区别 [英] Difference between $locationChangeStart, $routeChangeStart, and $stateChangeStart

查看:27
本文介绍了$locationChangeStart、$routeChangeStart 和 $stateChangeStart 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这三个有什么区别,它们对应的 $locationChangeSuccess$routeChangeSuccess$stateChangeSuccess.

I wonder what's the difference with these three, with their corresponding $locationChangeSuccess, $routeChangeSuccess, and $stateChangeSuccess.

推荐答案

$locationChangeStart:这使用 $location 提供程序并在 URL 更改时进行广播.位置更多地是指特定 URL 的路径.它更像是普通的 JavaScript,您可以更改为应用程序中的任何路径,而不管它是在您的应用程序中定义为路由还是状态.

$locationChangeStart: this uses the $location provider and broadcasts whenever the URL changes. Location refers more to a Path of a specific URL. It's more like plain JavaScript, you can change to any path in your application and it doesn't matter if it's defined on your app as route or state.

$routeChangeStart:这使用 $route 提供程序,它是相同的,它在路由更改时broadcasts(与 ngRoute 一起使用的默认 Angular 路由器).这用于在控制器和视图之间建立链接.

$routeChangeStart: this uses the $route provider, and it's the same, it broadcasts when the route changes (default Angular router used with ngRoute). This is used to do a link between controllers and views.

$stateChangeStart:它发生在您的状态更改时,并且在转换开始时广播.它由 ui-router 使用,它提供了一个不同的(更高级的)routeprovider 实现.状态允许您映射和访问关于不同状态的不同信息,您可以通过 $stateParams 在状态之间轻松传递信息.

$stateChangeStart: it happens when your state changes, and this broadcasts when a transition begins. It is used by ui-router which provides a different (more advanced) implementation of routeprovider. States allow you to map and access different information about different states and you can easily pass information between states via $stateParams.

它们非常相似,实际上它们具有相同的名称,但主要区别取决于您的应用程序使用的路由.如果您使用的是 angular 路由器,请坚持使用路线,但是,如果您使用 ui-router,请坚持使用状态.这是我可以给你的实用建议.

They are quite similar, in fact they share the same names, but the main differences depends on the routing your application uses. If you are using angular router then stick to routes, however, if you are using ui-router, stick to states. This is practical advice I can give you.

这篇关于$locationChangeStart、$routeChangeStart 和 $stateChangeStart 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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