问题描述
在 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 路由器?如果是这样,wiki 指定差异:
Are you referring to the AngularUI Router? If so, the wiki specifies the differences:
$state.go(to [, toParams] [, options])
返回一个表示转换状态的 Promise.
Returns a Promise representing the state of the transition.
转换到新状态的便捷方法.$state.go 在内部调用 $state.transitionTo 但自动将选项设置为 { location: true, inherit: true, relative: $state.$current, notify:真}.这使您可以轻松地使用绝对路径或相对路径,并仅指定您想要更新的参数(同时让未指定的参数从当前状态继承).
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.
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.
这篇关于Angular ui-router 中 $state.transitionTo() 和 $state.go() 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)