加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 08:43:59 所属栏目:安全 来源:网络整理
导读:我使用ui路由器来表示我的AngularJS应用程序中的状态。在其中我想更改状态,而不更改URL(基本上“详细视图”更新,但这不应影响URL)。 我使用 a ui-sref =“item.detail({id:item.id})”以显示详细信息,但这只有在我在$ stateProvider中指定像url:“/ det
我使用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的详细信息

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读