7

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);

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
    }

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.

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

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

Any ideas what I am doing wrong?

halfer
  • 19,824
  • 17
  • 99
  • 186
Martin
  • 23,844
  • 55
  • 201
  • 327
  • You have the answer [here, on this link](http://stackoverflow.com/questions/28248236/angular-ui-router-passing-data-between-states-without-url) – Igor Janković Aug 12 '16 at 08:01

1 Answers1

6

There is a working plunker

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'})">

There is a state as is above:

.state('home.showinfo', {
    url: 'info/info/:id',
    templateUrl: 'showinfo.tpl.html',
    resolve: {
        info: function($stateParams){
            return $stateParams.info;
        }
    },
    params: {
        info: null
    }
})

Check it here

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335