Angular LocalStorage Service

(function () { 'use strict'; angular.module('app') .factory('Storage', [function () { var fn = {}; fn.has = function (key) { var value = window.localStorage.getItem(key); return !!value; } fn.get = function (key) { if (!fn.has(key)) return false; return JSON.parse(window.localStorage.getItem(key)); } fn.set = function (key, value) { var v = (typeof value === 'object') ? JSON.stringify(value) : value; window.localStorage.setItem(key, v); } return fn; }]); })();
This snippets just makes a bit easier to use localStorage in your angular app with a less verbose api.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.