ngStorage icon indicating copy to clipboard operation
ngStorage copied to clipboard

BUG: On $reset if load the same values the Local Storage is clear.

Open pdorgambide opened this issue 6 years ago • 1 comments

Bug: Browser storage mantein clear when $localstorage.$reset and try to load the same data. $localstorage.$reset($localstorage); // Brower Local Storage are empty

The cause: On $reset the _last$storage variable is not clear and this make that on $apply the conditon always is true: if (!angular.equals($storage, _last$storage))

Fix (suggested):

                  $reset: function(items) {
                            for (var k in $storage) {
                                '$' === k[0] || (delete $storage[k] && webStorage.removeItem(storageKeyPrefix + k));
                            }
                            _last$storage={}; 
                            return $storage.$default(items);
                        },

pdorgambide avatar Oct 03 '18 14:10 pdorgambide

A hack that would work without changing the code would be:

const items = $localstorage;
$localstorage.$reset();
$localstorage.$apply(); // force storing the data to make sure _last$storage is overwritten.
$localstorage.$reset(items);

dlemstra avatar Dec 23 '20 14:12 dlemstra