gpt4 book ai didi

angularjs - AngularJS UI-Router 中 ui-sref 和 $state.go 之间的区别

转载 作者:行者123 更新时间:2023-12-02 19:23:34 25 4
gpt4 key购买 nike

ui-sref 之间有功能区别吗?和$state.go()

ui-sref用于<a>...</a>$state.go('someState')用于 Controller 中。

在 HTML 中,我会使用:

<a ui-sref="currentState.state1">Link</a>

而在函数中我会使用类似的东西:

if(someCondition) {
$state.go('currentState.state1');
}

那么,是这样还是我需要在 $state.go() 之后添加一些内容? ?假设当前状态是 currentState .

最佳答案

ui-sref$state.go 之间没有功能差异。请参阅文档

Activating a state

There are three main ways to activate a state:

  • Call $state.go(). High-level convenience method.
  • Click a link containing the ui-sref directive.
  • Navigate to the url associated with the state.

所以,这些最终都是做同样的事情,正如我们在 ui-sref directive 的代码中看到的那样:

...
element.bind("click", function(e) {
var button = e.which || e.button;
if ( !(button > 1 || e.ctrlKey || e.metaKey || e.shiftKey || element.attr('target')) ) {

var transition = $timeout(function() {
// HERE we call $state.go inside of ui-sref
$state.go(ref.state, params, options);
});

它确实调用了$state.go()

也如此处所讨论的:ui-sref :

ui-sref='stateName' - Navigate to state, no params. 'stateName' can be any valid absolute or relative state, following the same syntax rules as $state.go()

关于angularjs - AngularJS UI-Router 中 ui-sref 和 $state.go 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24526801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com