$ state.transitionTo()和$ state.go()在AngularJS之间的差异 [英] Difference between $state.transitionTo() and $state.go() in 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?
推荐答案
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屋!