Difference between $state.transitionTo() and $state.go() in Angular ui-router(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 路由器?如果是这样,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() 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Angular ui-router 中 $state.transitionTo() 和 $state.go() 之间的区别
基础教程推荐
- npm start 错误与 create-react-app 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
