I want to pass a custom object to another state via $state.go()
in UI-Router.
var obj = {
a: 1,
b: 2,
fun: function() {
console.log('fun');
}
}
$state.go('users', obj);
But I need to run fun()
in target state, so I can't pass this object in URL parameter. In target controller, I tried to fetch the value of obj
via $stateParams
but got empty object {}
:
function UserCtrl($stateParams) {
console.log($stateParams); // will be empty
}
So how to pass obj
to state "users" correctly?
Template:home.html
Define state with parameters like this:
when calling pass parameter like this:
in the controller UserCon receive parameter like:
User $state is one of the parameter in the controller defined like