From 04df295c815c1015394031acd9f73e52dbb90d91 Mon Sep 17 00:00:00 2001 From: Darlan Alves Date: Tue, 17 Sep 2013 23:33:52 -0300 Subject: [PATCH] Fix returned value when the previously store value was null --- localStorageModule.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/localStorageModule.js b/localStorageModule.js index 02efee5..6f23c6a 100644 --- a/localStorageModule.js +++ b/localStorageModule.js @@ -78,9 +78,10 @@ angularLocalStorage.service('localStorageService', [ } var item = localStorage.getItem(prefix+key); - if (!item) { - return null; - } + // angular.toJson will convert null to 'null', so a proper conversion is needed + // FIXME not a perfect solution, since a valid 'null' string can't be stored + if (!item || item === 'null') return null; + if (item.charAt(0) === "{" || item.charAt(0) === "[") { return angular.fromJson(item); }