我在传递一个不是 url 参数的参数时遇到问题。
我基本上有以下点击事件
let stateParams = {
id: event.info.id,
info: event.info
};
this.$state.go('home.showinfo', stateParams);
我仔细检查了 stateParams 包含 id 和 info 对象。
然后我在状态上有以下设置
.state('home.showinfo', {
url: 'info/info/:id',
resolve: {
info: function($stateParams){
return $stateParams.info;
}
},
params: {
info: null
}
在我的 Controller 中,我正在检查 $stateparams 的值,我看到了 id(URL 也包含 ID),但 info 对象为空。它始终为空。我只想能够在 Controller 中访问它。 “this.info”也为空。
我在 resole 中放置了一个断点,并且 info 为空。
我试过删除
params:{}
上面还是什么都没有。任何想法我做错了什么?
最佳答案
有a working plunker
代码应该可以工作,检查两次调用方。这些链接将执行预期的操作:
<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
}
})
查一下 here
关于angularjs - 用户界面路由器 : passing in a param that not in the url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38912748/