I am encountering an issue when trying to stringify and parse a URL object.
To set the location in Angular's $location, I simply stringify my object like this:
currentUrl = {"module1": {"is": true}}
$location.search(JSON.stringify(currentUrl));
The URL parses correctly, but when I try to retrieve it from the URL, I get this back:
console.log($location.search());
---
Object {{"module1":{"is":true}}: true}
How can I convert this back into an object so that I can use it? When I try:
JSON.parse($location.search());
I get a syntax error. Could this be due to how the search method returns the object? I'm a bit confused and could use some assistance. Thank you!
After setting it in the URL with:
$location.search(JSON.stringify(currentUrl));
What steps should I take to return it to its original form:
{"module1" : {"is" : true} }
Edit -
It seems that the JSON object is being set as the key in the location, like:
{ "mystrigifiedobject": true }
Edit2:
Following the first edit, I was able to resolve it (assuming it's set as the locations object key) like this:
currentUrl = $location.search();
currentUrl = JSON.parse(Object.keys(currentUrl));
console.log(currentUrl);
This solution feels a bit odd. Am I doing something incorrect here?