javascript - 使用 ui-router 服务在 ionic 框架中使用 ui-sref 和 href(在哪里使用)之间的区别

标签 javascript angularjs ionic-framework

我正在研究 ionic 框架。所以我对使用 ui-sref 和 href 感​​到困惑。例如,对于选项卡,我们使用 ui-sref,因为我们可以将各种状态都链接到一些主要(基本)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),我的仪表板页面有选项卡,现在有各种不同的状态 例如。

//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。 如果我在那里使用 ui-sref,editclaim 模板也有选项卡,它会正常工作吗,因为目前这是问题所在。 所以我想知道我是否必须保持某种状态直到那里。谢谢。

最佳答案

here should i use ui-sref or href.

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

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.

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

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

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


开发者很少使用href例如在大列表中以获得更好的性能以避免额外的观察者,但希望它不是你的情况

关于javascript - 使用 ui-router 服务在 ionic 框架中使用 ui-sref 和 href(在哪里使用)之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43823184/

相关文章:

javascript - 在滴管插件jquery中滴下图像预览

javascript - 注入(inject) jQuery、jQuery UI 和插件,无版本冲突

javascript - 移动设备上的Java单击事件

android - 如何使用 ionic 在图库中显示下载的图像

android - 你能在 Ionic 1 上使用 Native Storage 吗?

javascript - 将字节数组写入二进制文件 Javascript

javascript - 将项目添加到 AngularJS 中的 promise 数组

javascript - 当输入值更改时,将多个输入字符串推送到范围数组 (AngularJS)

javascript - 多个条目后字符串替换然后拆分

ios - phonegap-push-plugin 在 iOS 中不起作用