I am wondering if it is possible to pass JSON object within the stateParams in angular ui router. So far, when I am trying to pass an object, I log it and get "[object Object]".
I did some research, and found this topic: AngularJS: Pass an object into a state using ui-router however, none of the answers work for me.
So far, I've tried this:
<a ui-sref="profile({user: data})"></a>
where:
.state('profile', {
url: "/profile/:user",
templateUrl: "profile/profile.html",
controller: "ProfileCtrl",
params : { user: null }
})
Any ideas?
EIDT: and variable data should look like that:
{
"_id": "5612d4f138cf125420331d1e",
"index": 0,
"guid": "2fa8a98f-902e-4dfd-a8ac-24e3fdc52d8c",
"isActive": false,
"balance": "$3,957.95",
"picture": "xxxxx",
"age": 23,
"eyeColor": "brown",
"name": "xxxxxxx",
"gender": "female",
"company": "xxxx",
"email": "xxxx@xxxx.xxx",
"phone": "xxxxx",
"address": "xxxxx"}
And the link that I get from the browser is the following "http://localhost:8888/#/profile/%5Bobject%20Object%5D"
So far, here is the trick that worked for me:
Using
ng-click="goToProfile(data)"
instead of ui-sref, and the function is
$scope.goToProfile= function(data){
var object = data;
$state.go('profile', {user: object}) ;
};