$ state.transitionTo()和$ state.go()在AngularJS之间的差异 [英] Difference between $state.transitionTo() and $state.go() in AngularJS

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

问题描述

在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路由器?如果是这样,维基<一href=\"https://github.com/angular-ui/ui-router/wiki/Quick-Reference#stategoto--toparams--options\">specifies差异的:

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

$ state.go(设置为[,toParams] [,选项])

返回无极重新presenting过渡的状态。

Returns a Promise representing the state of the transition.

有关过渡到一个新的状态的便捷方法。 $ state.go 要求 $ state.transitionTo 在国内,而且会自动设置选项 {位置:真的,继承:真实的,相对的:$ $状态电流,通知:真正} 。这使您可以轻松地使用绝对或相对路径,并指定唯一的参数,你想更新(而让未指定的参数从当前状态继承)。

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(于toParams [,选项])

返回无极重新presenting过渡的状态。

Returns a Promise representing the state of the transition.

有关过渡到一个新的国家的低级别方法。 $ 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.

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

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