0

I am trying to pass an object as param in my url, but i am getting this weird formation.

http://localhost:8080/#/%5Bobject%20Object%5D => [object Object]

Below is my code on how i am sending the object.

var user = {"user":item};
$state.go("myState",user);

In my routes

.state('myState',{
   url: "/:user",
   templateUrl: "user.html",
   controller: 'User',                  
});

When i try to access the view user page, i get the above url and the data is not able to be accessed via $stateParams.user as its a string [object Object]

I am using ui-router version v0.2.15 with angular 1.3.4

ShankarGuru
  • 627
  • 1
  • 6
  • 17

1 Answers1

1

If you're just wanting to pass an object from one state's controller to another, you can't use the URL state parameters as these must be a string in order to work in the URL.

What you can do is use the params state config property.

$stateProvider.state('myState', {
    url: 'whatever',
    templateUrl: 'user.html',
    controller: 'User',
    params: {
        user: null
    }
});

Now you can transition to the myState state and pass a complex object

$state.go('myState', {user: item});

and your User controller can reference $stateParams.user.

Phil
  • 157,677
  • 23
  • 242
  • 245
  • 1
    This is how i was doing, the problem is when you refresh the page... it would loose the data... and.. here is a thread on this.. but its not working in my case.. http://stackoverflow.com/questions/31979798/stateparams-getting-null-after-page-refresh – ShankarGuru Dec 03 '15 at 04:05