我有一个分页系统,由我从 JSON 文件检索的项目组成。我可以添加/删除其中任何一个。我想将每个项目与配置 View 的链接关联起来(每个项目都有相同的模板,但必须有自己的配置)。我正在寻找一种使用 ui.router 来执行此操作的正确方法。这是我的路由:
app.js:
app.config(function ($stateProvider) {
$stateProvider.state("itemslist", {
url:"/itemslist",
views: {
'launcher':{
controller:"ItemsListCtrl",
templateUrl:"ItemsList.html"
}
}
})
...
}
和 html 文件:
ItemList.html:
<ul>
<li ng-repeat="item in listItem">
<b>{{item.text}} -</b>
<button ui-sref="dynamic state">CONFIG.</button>
</li>
</ul>
这里的“动态状态”可能类似于“config?item.id”。在这种情况下路由将如何工作?这可能吗?
最佳答案
使用状态参数: https://github.com/angular-ui/ui-router/wiki/url-routing
ui-sref="config({itemId: item.id})"
$stateProvider.state("config", {
url:"/itemconfig/:itemId",
...
})
关于javascript - 如何将唯一的 ui-sref 与动态列表中的每个项目相关联?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39036822/