简体   繁体   English

如何将唯一的ui-sref与动态列表中的每个项目相关联?

[英]How to associate a unique ui-sref to every items in a dynamic list?

I have a pagination system composed of items I retrieve from a JSON file. 我有一个分页系统,该系统由从JSON文件检索的项目组成。 I can add/remove any of them. 我可以添加/删除其中任何一个。 I want to associate to each of these items a link to a configuration view (each item has the same template but it has to have his own configuration). 我想将每个链接关联到配置视图(每个条目具有相同的模板,但必须具有自己的配置)。 I'm looking for a proper way to do this using ui.router . 我正在寻找使用ui.router的正确方法。 Here's what my routing looks like : 这是我的路由的样子:

app.js : app.js:

app.config(function ($stateProvider) {

        $stateProvider.state("itemslist", {
            url:"/itemslist",
            views: { 
                'launcher':{
                    controller:"ItemsListCtrl",
                    templateUrl:"ItemsList.html"
                }
            }
        })
        ...
}

And the html file : 和html文件:

ItemList.html : ItemList.html:

<ul>
    <li ng-repeat="item in listItem">
        <b>{{item.text}} -</b>
        <button ui-sref="dynamic state">CONFIG.</button>
    </li>
</ul>

Here the 'dynamic state' could be something like "config?item.id". 这里的“动态状态”可能类似于“ config?item.id”。 How would the routing work in this case ? 在这种情况下,路由如何工作? Is this even possible ? 这有可能吗?

Use state params: https://github.com/angular-ui/ui-router/wiki/url-routing 使用状态参数: https : //github.com/angular-ui/ui-router/wiki/url-routing

ui-sref="config({itemId: item.id})"

$stateProvider.state("config", {
    url:"/itemconfig/:itemId",
    ...
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM