ui-router:传递不在URL中的参数? [英] ui-router: passing in a param that not in the url?

查看:116
本文介绍了ui-router:传递不在URL中的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在传递不是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和信息对象.

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对象为null.它始终为空.我只希望能够在控制器中访问它.同样,"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.

我在底盘中添加了一个断点,而info为空.

I put a breakpoint in the resole and info is null.

我尝试删除上面的params:{},但还是一无所获.

I have tried removing the params:{} above and still nothing.

有任何想法我在做什么错吗?

Any ideas what I am doing wrong?

推荐答案

工作中的活塞

该代码应该正常工作,请两次检查调用方.这些链接将完成预期的操作:

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中的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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