使用ui-router服务在离子框架中使用ui-sref和href(在何处使用)之间的区别 [英] difference between using ui-sref and href(where to use) in ionic framework using ui-router service

查看:48
本文介绍了使用ui-router服务在离子框架中使用ui-sref和href(在何处使用)之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究离子骨架.因此,我对使用ui-sref和href感到困惑.例如,对于选项卡,我们使用ui-sref,因为我们可以将各种状态都链接到某个主(基本)URL.

I am working on ionic framework. So I am confused with using ui-sref and href. For example for tabs we use ui-sref as we can have various states all linked to some main (base) url.

例如

  .state('dashboard', {
    url: "/dashboard",
    templateUrl: 'templates/dashboard.html',
    controller: 'dashboardCtrl'
})

 .state('dashboard.active', {
    url: '/active',
     views: {
              'active': {
                templateUrl:  'templates/active.html',
                controller: 'ActiveCtrl'
              }
            }

})

我的仪表板页面上有多个选项卡,如果我想从这些状态或模板之一移至其他模板(例如,移至active.html),则现在具有各种不同的状态例如.

My dashboard page has tabs whish have various various states now if I want to move to a diffrent template from one of these states or templates (eg to active.html) eg.

//active.html

 <li class="item">
   <a class="button button-positive" ui-sref="dashboard.editClaim"> Edit Claim
   </a>
 </li>

 <li class="item">
   <a class="button button-positive" href="#/dashboard/editClaim"> Edit Claim
   </a>
 </li>

在这里我应该使用ui-sref或href.另外editclaim模板具有选项卡,如果我在那里使用ui-sref,它将正常工作,因为当前是问题所在.所以我想知道我是否必须保持某种状态.谢谢.

here should i use ui-sref or href. Also editclaim template has tabs should i use ui-sref there and will it work fine because currently that is the problem. So I am wondering if I have to maintain some state till there. Thank you.

推荐答案

我应该在这里使用ui-sref或href.

here should i use ui-sref or href.

从文档中: https://github.com/angular-ui/ui-router/wiki/Quick-Reference#ui-sref

将链接(标记)绑定到状态的指令.如果州有关联的网址,该指令将自动生成&更新通过$ state.href()方法的href属性.点击链接将使用可选参数触发状态转换.还在链接上单击鼠标中键,单击鼠标右键和Ctrl键并单击由浏览器本地处理.

A directive that binds a link ( tag) to a state. If the state has an associated URL, the directive will automatically generate & update the href attribute via the $state.href() method. Clicking the link will trigger a state transition with optional parameters. Also middle-clicking, right-clicking, and ctrl-clicking on the link will be handled natively by the browser.

<一个ui-sref ="home"> Home</a> 转换为:

<a href="#/home" ui-sref="home">Home</a>

如果您决定使用 ui-router ,请使用 ui-sref .这是最佳做法.您可以将代码关联的URL更改为相同状态,而无需维护链接.

Use ui-sref if you decided to use ui-router. This is a best practice. You can change in your code associated URL for the same state and you don't need to maintain your links.

开发人员很少在大型列表中使用 href 以获得更好的性能,以避免其他观察者,但希望不是您的情况

Developers rarely use href for example in big lists for better performance to avoid additional watchers, but hope its not your case

这篇关于使用ui-router服务在离子框架中使用ui-sref和href(在何处使用)之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆