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

在ui-router中用于AngularJS的没有URL的状态的参数

我使用ui路由器来表示我的AngularJS应用程序中的状态。在其中我想更改状态,而不更改URL(基本上“详细视图”更新,但这不应影响URL)。

我使用< a ui-sref =“item.detail({id:item.id})”>以显示详细信息,但这只有在我在$ stateProvider中指定像url:“/ detail-:id”这样的URL时才有效。

在我看来,当前状态只通过URL定义。

感谢您的答案,它确实帮助我在正确的方向,但我只是想添加一个更完整的描述。

在我的具体问题有一个复杂因素,因为我需要注入一个非URL参数的状态是一个子状态。这复杂的事情轻微。

params:[‘id’]部分在$ stateProvider声明中,如下所示:

$stateProvider.state('parent',{
    url: '/:parentParam',templateUrl: '...',controller: '...'
}).
state('parent.child',{
    params: ['parentParam','childParam'],controller: '...'
});

并且param名称连接到ui-sref属性,如下所示:

<a ui-sref=".child({ childParam: 'foo' })">

抓住的是这:

If the parent state also has a URL parameter then the child needs
to also declare that in its params array. In the example above “parentParam” must be included in the childstate.

如果不这样做,那么当应用程序初始化时将抛出一个模块错误。这在写入时的最新版本(v.0.2.10)至少是这样。

编辑

@gulsahkandemir指出

Declaration of params in a state deFinition has changed to params: {
id: {} } from params: [‘id’]

从changelog看,这似乎是从v0.2.11开始的情况

params can be found in the official docs的详细信息

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

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

相关推荐