I Would like to pass two object in state.go method like this:
$state.go('app.home', {
playSavedPlaylist:true,
playlistData: dataToPass
});
State app.home is following:
.state('app.home', {
url: '/home:playSavedPlaylist:playlistData',
views: {
'menuContent' :{
templateUrl: 'templates/home.html',
controller: 'HomeCtrl'
}
}
})
But if i'm trying to get params using:
console.log($stateParams);
I always get following:
Object {playSavedPlaylist: "true[object Object]", playlistData: ""}
But should it be:
Object {playSavedPlaylist: "true", playlistData: [object Object]}
How can i do it in right way please?
Many thanks for any advice.
You can add '/' to separate between parameters. Also url parameters can only be integers and strings, therefore objects must be converted to json, or not being included in the url.
.state('app.home', {
url: '/home/:playSavedPlaylist/:playlistData',
views: {
'menuContent' :{
templateUrl: 'templates/home.html',
controller: 'HomeCtrl'
}
}
});
$state.go('app.home', {
playSavedPlaylist:true,
playlistData: angular.toJson(dataToPass)
}
//, { location: false, inherit: false} <-- will exclude parameters from url
);
What is dataToPass
? an object?
You can't pass an object directly in the URL, so you should use a service in order to get the data that you need, you can only pass integer (ex: id, max, min) and string that doesn't contains forbidden char for URL (You can use URI encode).