参数状态,而无需在UI路由器网址AngularJS [英] Parameters for states without URLs in ui-router for AngularJS

查看:104
本文介绍了参数状态,而无需在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆