Pass object as parameter in $state.go Pass object as parameter in $state.go angularjs angularjs

Pass object as parameter in $state.go


Parse object to json:

var benefit = angular.toJson({ "x": "y"});

Define variable in state params:

.state('pages.claimed', {   url: '/claimed?params',   views: {     'page': {       templateUrl: 'templates/pages/claimed.html'     }   }})

Access to variable from controller via $stateParams:

var benefit = angular.fromJson($stateParams.benefit);

Here full doc

Edit:

There are several ways to pass an object to controller from url:

Via query params:

define options url: '/yoururl?a&b&c',

pass variables yoururl?a=1&b=2&c=3

Via url params:

define options url: '/yoururl/:a/:b/:c',

pass variables yoururl/1/2/3

For more complicated situations you can parse your object to json string and encode it with base64

Object: { a:1, b:2, c:3 }JSON String: {"a":1,"b":2,"c":3}Base64 Encoded string: eyJhIjoxLCJiIjoyLCJjIjozfQ==

define options url: '/yoururl?params'

pass variables yoururl?params=eyJhIjoxLCJiIjoyLCJjIjozfQ==

More info about base64


$state.go should be corrected like this

var benefit = { "x": "y"};$state.go('pages.claimed', { benefit: benefit });