微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angularjs – 在ui-router中动态构造的ui-sref属性

我是新来的,特别是ui-router。

这是一个链接

<a ui-sref="/topic/{{topic.id}}">SomeText</a>

链接动态填充。

所以当我尝试从我的配置访问该状态,如下所示:

.state('topics/:topicId',{
        url:"",templateUrl: "",controller: ""
    })

我收到这个错误消息:

Error: Could not resolve ‘/topics/myTopic’ from state ‘topics’

在上面:myTopic是一个变量名。

你几乎在那里只有参数必须是URL定义的一部分,而不是状态的名称
.state('topics',{
    url: '/{id:[0-9]{1,8}}',// we can also add some constraint,like int id only
    templateUrl: "",controller: ""
 })

并且如何调用它(其中currentItem.id将被动态注入作为某些ng重复的一部分)

<a ui-sref="topics({id:currentItem.id})">SomeText</a>

因为ui-sref表示:ui-sref =’stateName({param:value,param:value})。更多信息:

> ui router,URL Parameters
> ui-sref

原文地址:https://www.jb51.cc/angularjs/144085.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐