Hey everyone.
I’m having a little trouble with getting my head around localStorage, and especially the when it comes to dealing with objects. I understand that the guys at Ionic have put together a tutorial on localstorage but it’s the last 10% of what I’m trying to do is failing I believe.
Below, I’m basically trying to initialise an object in a localStorage key called ‘items’. Then when I submit the data from a form I am pushing an object onto the array in ‘keys’. However, while the initalised object is saving to localStorage the createNewContact function is not. Any ideas? Thanks heaps in advance!
window.localStorage['items'] = JSON.stringify([{
title: 'You Owe Me Now',
fullName: 'Cameron Bourke',
dollarAmount: '2',
description: 'You owe me $2 for downloading this app. Only kidding!! This is just an example of a "Theyo". Delete me now by swiping to the left and enjoy.'
}]);
$scope.contacts = JSON.parse(localStorage.getItem('items')) || [];
console.log(window.localStorage['items']);
$scope.createContact = function(u) {
$scope.contacts.push({ fullName: u.fullName,
title: u.title,
dollarAmount: u.dollarAmount,
description: u.description });
u.fullName = '';
u.title = '';
u.dollarAmount = '';
u.description = '';
$scope.modal.hide();
};
$scope.onItemDelete = function(item) {
$scope.contacts.splice($scope.contacts.indexOf(item), 1);
};