In my Angular application, I am attempting to save and retrieve data between pages using the following function:
$scope.storeData = function () {
var selections = $scope.devices;
console.log(selections);
sessionStorage.setItem('selectedHandsets', JSON.stringify(selections));
var ss = sessionStorage.getItem('selectedHandsets');
console.log(ss);
}
However, I have encountered a strange issue. The values 'selectedManufacturer' and 'selectedModel' that I need from selections
are visible in the console log output of console.log(selections)
.
Yet, when I check the contents of ss
(retrieved from sessionStorage.selectedHandsets
), those keys are mysteriously missing. Even though they were present during the setting of the data into selections, they vanish when logging ss
!
The structure of selections
is as follows:
[
[
{ ... },
{ ... },
selectedModel: { ... },
selectedManufacturer: { ... }
],
[
{ ... },
{ ... },
selectedModel: { ... },
selectedManufacturer: { ... }
]
]
If I wrap JSON.stringify()
around console.log(selections)
, the selectedModel and selectedManufacturer disappear. Can anyone explain why this is happening and suggest an appropriate solution?