Created
November 15, 2014 05:01
-
-
Save abelorian/ef6411d9a2aa47d88bec to your computer and use it in GitHub Desktop.
AngularJS service for HTML5 localStorage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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