Angular ui-router中$ state.transitionTo()和$ state.go()之间的区别 [英] Difference between $state.transitionTo() and $state.go() in Angular ui-router

查看:210
本文介绍了Angular ui-router中$ state.transitionTo()和$ state.go()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AngularJS中,我看到有时我们使用 $ state.transitionTo(),有时我们使用 $ state.go()。任何人都可以告诉我它们之间的差异以及何时应该使用另一个?

In AngularJS, I see sometimes we use $state.transitionTo() and sometimes we use $state.go(). Can anyone tell me how they differ and when one should be used over the other?

推荐答案

你指的是 AngularUI路由器?如果是这样,维基指定差异

Are you referring to the AngularUI Router? If so, the wiki specifies the differences:


$ state.go(to [,toParams] [,options])

返回表示转换状态的 Promise

转换到新状态的便捷方法。 $ state.go 在内部调用 $ state.transitionTo 但会自动将选项设置为 {location: true,inherit:true,relative:$ state。$ current,notify:true} 。这允许您轻松使用绝对路径或相对路径,并仅指定您要更新的参数(同时让未指定的参数从当前状态继承)。

Convenience method for transitioning to a new state. $state.go calls $state.transitionTo internally but automatically sets options to { location: true, inherit: true, relative: $state.$current, notify: true }. This allows you to easily use an absolute or relative to path and specify only the parameters you'd like to update (while letting unspecified parameters inherit from the current state).

$ state.transitionTo(to,toParams [,options])

返回 Promise 表示转换状态。

转换到新状态的低级方法。 $ state.go()在内部使用 transitionTo 。在大多数情况下,建议使用 $ state.go()

Low-level method for transitioning to a new state. $state.go() uses transitionTo internally. $state.go() is recommended in most situations.

这篇关于Angular ui-router中$ state.transitionTo()和$ state.go()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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