So lets say I want to define an var array=['a','b','c']
How do I pass this array into localStorage ?
Should I just simply write $localStorage.data = array;
?
And also how to check if that array $localStorage.data
is not empty and not undefined?
How do I pass this array into localStorage ? Should I just simply write $localStorage.data = array;?
Yes, you simply put it like this:
$localStorage.data = array
And also how to check if that array $localStorage.data is not empty and not undefined?
Check it like simple variable
if($localStorage.data){
console.log('empty');
} else{
console.log('Data', $localStorage.data);
}
Right from AngularJS homepage: "Unlike other frameworks, there is no need to [...] wrap the model in accessors methods. Just plain old JavaScript here." Now you can enjoy the same benefit while achieving data persistence with Web Storage.