I have set up an array in my application that looks like this [{pseudo: "test", id: 0}, {pseudo: "Lucia", id: 2}]
Is there a way to preserve this array even when the app is closed? Additionally, I would like to access the array directly upon reopening the app, rather than when it is running in the background.
UPDATE: I attempted to achieve this by:
Storage :
var friend = ({
idx: id
});
var friend_json = JSON.stringify(friend);
sessionStorage.setItem("friend", friend_json);
The read operation only occurs the first time I open the app (placed right after my controller starts), but I receive a null value in the console log.
var friendStorage = [];
var storageFriendsNotified = window.localStorage;
var friend_json = sessionStorage.getItem("friend");
var friend = JSON.parse(friend_json);
console.log(angular.toJson(friend));
console.log(friend);
friendStorage.push(friend);
console.log(friendStorage);
console.log(angular.toJson(friendStorage));
UPDATE 2: $scope.isChecked is used for ng-class, I am trying to access the id of my json, but it appears in this format [[{"pseudo": pseudo, "id": id}]] ... friendsNotified[i].id does not seem to work
var friendsNotified = [];
$scope.isChecked = [];
var storageFriendsNotified = window.localStorage;
var friend_json = window.localStorage.getItem("info");
var friend = JSON.parse(friend_json);
if (friend != null){
friendsNotified.push(friend);
if (friendsNotified.length > 0) {
for (var i = 0; i < friendsNotified.length; i++) {
console.log(friendsNotified[[i]].id);
$scope.isChecked[friendsNotified[i].id] = "fa fa-check-circle-o pull-right";
}
}
}