Created
August 28, 2017 14:37
-
-
Save wholypantalones/086274a1498df684ae01306562dc92a3 to your computer and use it in GitHub Desktop.
Angular localStorage support run function
This file contains hidden or 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
// usage | |
// var thisThing = localStores.getItem('this thing); | |
.run(function ($window) { | |
function supports_html5_storage() { | |
try { | |
return 'localStorage' in window && window['localStorage'] !== null; | |
} catch (e) { | |
return false; | |
} | |
} | |
$window.sessionStorage.storage = supports_html5_storage(); | |
}).factory('localStores', function ($window) { | |
if ($window.sessionStorage.storage) { | |
return { | |
removeItem: function (args) { | |
return localStorage.removeItem(args); | |
}, | |
getItem: function (args) { | |
return JSON.parse(localStorage.getItem(args)); | |
}, | |
setItem: function (args1, args2) { | |
return localStorage.setItem(args1, JSON.stringify(args2)); | |
} | |
}; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment