angularLocalStorage
angularLocalStorage copied to clipboard
Public get/set/remove methods will execute localStorage code if $cookieStore method cause exception
For the public get(), set() and remove() methods, if supported == false and any type of exception occurs, the code specific to localStorage will attempt to run, even though supported == false.
For example, this is the current set():
set: function (key, value) {
if (!supported) {
try {
$cookieStore.put(key, value);
return value;
} catch(e) {
$log.log('Local Storage not supported, make sure you have angular-cookies enabled.');
}
}
// THE FOLLOWING LINES RUN WHEN THE CATCH(E) ABOVE IS TRIGGERED
var saver = angular.toJson(value);
storage.setItem(key, saver);
return privateMethods.parseValue(saver);
},
Suggest doing the following:
set: function (key, value) {
if (!supported) {
try {
$cookieStore.put(key, value);
return value;
} catch(e) {
$log.log('Local Storage not supported, make sure you have angular-cookies enabled.');
}
}
else { // THIS CODE WILL NOW ONLY EVER EXECUTE IF (supported)
var saver = angular.toJson(value);
storage.setItem(key, saver);
return privateMethods.parseValue(saver);
}
},