参数状态,而无需在UI路由器网址AngularJS

编程入门 行业动态 更新时间:2024-10-24 10:20:02
本文介绍了参数状态,而无需在UI路由器网址AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用的UI路由器重新present状态在我的AngularJS应用程序。在这里面我想改变状态不改变URL(基本上是详细视图被更新,但这不应该影响URL)。

I am using ui-router to represent states in my AngularJS app. In it I'd like to change the state without changing the URL (basically a "detail view" is updated but this should not affect the URL).

我用<一个UI的SREF =item.detail({ID:item.id})> 来显示细节,但这只适用于如果我指定一个像的URL网址:。/ detail-:ID在我的 $ stateProvider

I use <a ui-sref="item.detail({id: item.id})"> to display the detail but this only works if I specify a URL like url: "/detail-:id" in my $stateProvider.

在我看来,目前的状态是通过URL只定义了。

It seems to me that the current state is only defined through the URL.

推荐答案

谢谢您的回答,这也帮助我在正确的方向,但我只是想增加一个更完整的描述。

Thanks for your answer, it did help me in the right direction but I'd just like to add a more complete description.

在我的具体问题出现了,因为国家我需要注入非URL参数是一个孩子状态的复杂因素。这种复杂的事情咯。

In my specific issue there was a complicating factor because the state I needed to inject a non-URL parameter to was a child state. That complicated things slightly.

的 PARAMS:['身份证'] 部分去在这样的 $ stateProvider 声明:

The params: ['id'] part goes in the $stateProvider declaration like this:

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

和帕拉姆名称连接到 UI-SREF 属性是这样的:

And the param name is connected to the ui-sref attribute like this:

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

和渔获是这样的:

如果父状态也有一个URL参数那么孩子的需要  也宣布在其 PARAMS 阵列。在上面的parentParam的例子中,必须被包括在的ChildState

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)的时间。

If you don't do that then a module-error will be thrown when the application is initialized. This is at least true on the latest version at the time of writing (v.0.2.10).

修改

@gulsahkandemir指出

@gulsahkandemir points out that

在一个状态定义则params的声明已更改为params:一个{  ID:{}}从PARAMS:['身份证']

Declaration of params in a state definition has changed to params: { id: {} } from params: ['id']

在更新日志来看,这似乎是从v0.2.11开始的情况下

Judging by the changelog, this seems to be the case starting from v0.2.11

细节可以在官方文档中找到

更多推荐

参数状态,而无需在UI路由器网址AngularJS

本文发布于:2023-11-23 01:41:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619647.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由器   状态   参数   网址   UI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!