I'm trying to pass nested objects as query parameters from my AngularJS Controller using the following code:
$scope.redirect = function () {
const params = $httpParamSerializer({
initval: {
user: {
id: 1,
name: 'Username',
}
}
})
$location.path('/url-to-other-controller').search(params);
})
When it comes to retrieving this query string in another controller and treating it as an object, I've experimented with different approaches and settled on the following code:
let qs = $location.search();
const initval = JSON.parse(qs.initval);
let userId = initval.user.id;
I'm unsure if my approach is optimal, especially since I have to parse the initial parameter (initval).
The main issue at hand is how to correctly handle query strings that are originally objects in AngularJS. Additionally, I'm curious if there's a more efficient way to send objects as query parameters.