Open hugomenesesp opened 8 years ago
Would you be able to provide a plnkr or something with the code that produces this error?
do the plnkr pls
I did update the description.
@egilkh: Here's an example code:
var app = angular.module('app', []);
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'main.html', //Contains a single button that executes ng-click="onClick()"
controller: 'MainController'
}).
when('/popup', {
templateUrl: 'popup.html',
controller: 'PopupController'
}).
otherwise({
redirectTo: '/'
});
}]);
app.controller('MainController', function ($scope, $sessionStorage, $localStorage, $window, $interval) {
var popupWindow = null;
$scope.onClick = function () {
//Try to close window if is opened
if (popupWindow && !popupWindow.closed) {
popupWindow.close();
}
$localStorage['A'] = {
B: 'localstorage-main'
};
$sessionStorage['A'] = {
C: 'sessionstorage-main'
};
var checkWindow = function () {
if (!(popupWindow !== undefined && popupWindow !== null && popupWindow.closed === false)) { //Popup closed
$interval.cancel(pollTimer);
var a = $sessionStorage['A']['C'];
console.info("Value of A.C: " + a);//Undefined
//$sessionStorage.A contains {B: 'localstorage-main', D: 'localstorage-second'} and should contain {C: 'sessionstorage-main'}
}
};
popupWindow = $window.open('#!/popup');
pollTimer = $interval(checkWindow, 600);
}
});
app.controller('PopupController', function ($scope, $localStorage, $window) {
$localStorage['A']['D'] = 'localstorage-second';
$window.close()
});
Hi I'm experiencing the same issue: something goes totally wrong:
Hi, it seems like a bug by creating session storage. Session storage is subscribed to the 'storage' event:
$window.addEventListener && $window.addEventListener('storage', function(event) {
...
});
but events are coming in by changing the local storage. If both storages contain the same key and the value in local storage was changed then the session storage becomes corrupted because it will be updated by the value from the local storage.
I too see this issue and was wondering what the intended functionality is support to be? Is the intention to somewhat synchronize between local and session storage? If not, then the event listed below should determine which storage is the source of the generated event and update accordingly. I didn't dig much to see the browser compatibility
https://developer.mozilla.org/en-US/docs/Web/API/StorageEvent
storageArea nsIDOMStorage Represents the Storage object that was affected. Read only.
https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API
I'm experiencing this issue as well. On deleting or modifying a $localStorage value the changes propagate through other open windows. $sessionStorage had the same change made on every window. It's unclear how to create a new window with sessionStorage that doesn't pollute the other windows with the same changes.
ngStorage seems to confuse $sessionStorage and $localStorage, following this flow:
An execution screenshot can be seen here: http://prntscr.com/8ow3bh