Skip to content

Instantly share code, notes, and snippets.

@abelorian
Created November 15, 2014 05:01
Show Gist options
  • Save abelorian/ef6411d9a2aa47d88bec to your computer and use it in GitHub Desktop.
Save abelorian/ef6411d9a2aa47d88bec to your computer and use it in GitHub Desktop.
AngularJS service for HTML5 localStorage
'use strict'
angular.module('app.datosLocalesService', [])
.service('DatosLocalesService', function() {
return {
isAvalaible: function(){
if(typeof(Storage)!=="undefined")
{
return true;
}
else
{
return false;
}
},
getItem: function(key) {
return JSON.parse(localStorage.getItem(key));
},
setItem: function(key, value){
return localStorage.setItem(key, JSON.stringify(value));
},
getItemById: function(id, key){
var input = JSON.parse(localStorage.getItem(key));
var i=0, len=input.length;
for (; i<len; i++) {
if (input[i].objectId === id) {
console.log('encontrado!!!');
return input[i];
}
}
return null;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment