From f6e4ea9e5b06a3735836c26f89f4e131b0216b54 Mon Sep 17 00:00:00 2001 From: Gihan S Date: Wed, 3 Jul 2013 21:46:05 +0530 Subject: [PATCH] Added javascript array auto stringyfy and reverse when adding and getting from localstorage. --- localStorageModule.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/localStorageModule.js b/localStorageModule.js index 3a52de7..4dc9133 100644 --- a/localStorageModule.js +++ b/localStorageModule.js @@ -1,3 +1,4 @@ + /* Start angularLocalStorage */ var angularLocalStorage = angular.module('LocalStorageModule', []); @@ -52,7 +53,7 @@ angularLocalStorage.service('localStorageService', [ if (typeof value == "undefined") value = null; try { - if (angular.isObject(value)) { + if (angular.isObject(value) || angular.isArray(value)) { value = angular.toJson(value); } localStorage.setItem(prefix+key, value); @@ -76,7 +77,7 @@ angularLocalStorage.service('localStorageService', [ var item = localStorage.getItem(prefix+key); if (!item) return null; - if (item.charAt(0) === "{") { + if (item.charAt(0) === "{" || item.charAt(0) === "[") { return angular.fromJson(item); } return item;