我使用< 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: '...' });
<a ui-sref=".child({ childParam: 'foo' })">
抓住的是这:
If the parent state also has a URL parameter then the child needs
to also declare that in itsparams
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 举报,一经查实,本站将立刻删除。