在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的详细信息

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...