Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions angular-local-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ angularLocalStorage.provider('localStorageService', function() {
var cookie = this.cookie;
var notify = this.notify;
var storageType = this.storageType;
var webStorage = $window[storageType];
var webStorage;

// When Angular's $document is not available
if (!$document) {
Expand All @@ -96,6 +96,7 @@ angularLocalStorage.provider('localStorageService', function() {
// that exceeded the quota."
var key = deriveQualifiedKey('__' + Math.round(Math.random() * 1e7));
if (supported) {
webStorage = $window[storageType];
webStorage.setItem(key, '');
webStorage.removeItem(key);
}
Expand All @@ -107,6 +108,8 @@ angularLocalStorage.provider('localStorageService', function() {
return false;
}
}());



// Directly adds a value to local storage
// If local storage is not available in the browser use cookies
Expand All @@ -131,7 +134,7 @@ angularLocalStorage.provider('localStorageService', function() {
if (angular.isObject(value) || angular.isArray(value)) {
value = angular.toJson(value);
}
webStorage.setItem(deriveQualifiedKey(key), value);
if (webStorage) {webStorage.setItem(deriveQualifiedKey(key), value)};
if (notify.setItem) {
$rootScope.$broadcast('LocalStorageModule.notification.setitem', {key: key, newvalue: value, storageType: this.storageType});
}
Expand All @@ -151,7 +154,7 @@ angularLocalStorage.provider('localStorageService', function() {
return getFromCookies(key);
}

var item = webStorage.getItem(deriveQualifiedKey(key));
var item = webStorage ? webStorage.getItem(deriveQualifiedKey(key)) : 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') {
Expand Down