我正在研究 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/