No $rootScope event for different windows
monster910 opened this issue · 6 comments
monster910 commented
I tried to watch a rootScope event between windows and it did not work
Producer method
$scope.changeStorage = function() {
localStorageService.set('test', new Date().toISOString());
};
Consumer code
$rootScope.$on('LocalStorageModule.notification.setitem', function(oldValue, newValue) {
console.log(oldValue);
console.log(newValue);
});
The only way to pickup changes is in the $window listener
$window.addEventListener('storage', function (event) {
console.log(event.key, event.newValue);
if (event.key === 'myApp.test') {
$timeout(function() {
$scope.dateValue = event.newValue;
}, 0);
}
});
Might want to look into establishing window listeners and propagating $rootScope events between windows since $rootScope are different objects by window.
I would do this based on some preference setting.
grevory commented
I welcome a PR on this idea.
monster910 commented
A PR?
grevory commented
Pull Request to fix it.
grevory commented
Actually, I think code to maintain scope data across windows should probably be handled independent of this module. It can get a bit hacky.
monster910 commented
I have a fork. I will see what I can do. Maybe the best thing is an example
test case for folks..
…On Wed, Apr 19, 2017 at 3:08 PM, Gregory Pike ***@***.***> wrote:
Actually, I think code to maintain scope data across windows should
probably be handled independent of this module. It can get a bit hacky.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#345 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAwcdEvZ37bEbyj-I_hjb03TyABbygMDks5rxmnWgaJpZM4MW4-A>
.
grevory commented
I'd like to see when you're done. Thanks.