加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 08:30:58 所属栏目:安全 来源:网络整理
导读:ui-sref和$ state.go()之间有什么功能差异吗? ui-sref用于 a … / a和$ state.go(‘someState’)在控制器中使用。 在HTML中,我将使用: a ui-sref="currentState.state1"Link/a 而在函数中,我将使用类似: if(someCondition) { $state.go('currentState.s
ui-sref和$ state.go()之间有什么功能差异吗?

ui-sref用于< a> …< / a>和$ state.go(‘someState’)在控制器中使用。

在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()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读