In the process of building a website with HTML5 and AngularJS, I am utilizing a controller to interact with the database and set up an array called $scope.array
.
Once the array is initialized, I store it in the session like this:
sessionStorage.array = $scope.array;
If there's already an existing array in the sessionStorage, I want to load that copy instead of creating a new empty array.
To achieve this, I have this logic in place:
if(sessionStorage.array)
$scope.array = sessionStorage.array;
else
$scope.array = [];
This ensures that $scope.array
contains the array data that I need to display via ng-repeat
in the HTML.
However, my issue arises when I refresh the page for the first time, as the $scope.array
object suddenly becomes an empty array (despite being initially populated with values from the database).
I'm looking for solutions on how to properly save the array in the session so that it never reaches the 'else' branch. Any advice would be greatly appreciated!