问题描述
我在传递一个不是 url 参数的参数时遇到问题.
I am having a problem passing in a param that's not a parameter in the url.
我基本上对点击事件有以下内容
I basically have the following on a click event
let stateParams = {
id: event.info.id,
info: event.info
};
this.$state.go('home.showinfo', stateParams);
我仔细检查了 stateParams 是否包含 id 和 info 对象.
I have double checked on the stateParams contains the id and also the info object.
然后我对状态进行了以下设置
I then have the following setup on the state
.state('home.showinfo', {
url: 'info/info/:id',
resolve: {
info: function($stateParams){
return $stateParams.info;
}
},
params: {
info: null
}
在我的控制器中,我正在检查 $stateparams 的值,我看到了 id(URL 也包含 ID),但 info 对象为空.它始终为空.我只想能够在控制器中访问它.this.info"也为空.
In my controller I am checking the value of $stateparams, and I see the id (also the URL contains the ID), but the info object is null. It's always null. I just want to be able to access it in the controller. Also "this.info" is also null.
我在 resole 中放置了一个断点并且 info 为空.
I put a breakpoint in the resole and info is null.
我尝试删除上面的 params:{}
,但仍然没有.
I have tried removing the params:{}
above and still nothing.
知道我做错了什么吗?
推荐答案
代码应该可以正常工作,请检查调用方两次.这些链接将执行预期的操作:
The code should be working, check twice the calling side. These links will do what is expected:
<a ui-sref="home.showinfo({id:1, info:'hi'})">
<a ui-sref="home.showinfo({id:2, info:'bye'})">
有一个状态如上:
.state('home.showinfo', {
url: 'info/info/:id',
templateUrl: 'showinfo.tpl.html',
resolve: {
info: function($stateParams){
return $stateParams.info;
}
},
params: {
info: null
}
})
在这里
这篇关于ui-router:传入一个不在 url 中的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!