-
Notifications
You must be signed in to change notification settings - Fork 461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep $localStorage in sync between tabs #6
Comments
OK, I think I have understood where the problem comes from. You simply have to replace, in lines if ('ngStorage-' === event.originalEvent.key.slice(0, 10)) {
event.originalEvent.newValue ? $storage[event.originalEvent.key.slice(10)] = angular.fromJson(event.originalEvent.newValue) : delete $storage[event.originalEvent.key.slice(10)]; The old line didn't make UPDATE: this comment has been updated after |
Hi @frapontillo, if you open the demo in multiple tabs, you'll see that changes do sync between tabs. Could you put your code in question onto Plunker so we can further check into this issue? |
Okay, I think I know what's going on - you were using jQuery, which moves the browser's innate But the truth is you don't need to use any watcher to achieve the sync'ing effect - ngStorage handles that for you outta-the-box. I would suggest you to remove the watcher in your code and see if this fixes the issue. I'll also update the doc to make this more apparent. |
Yes, I have also included jQuery. The thing is, I'm using UPDATE: to make it clear, this is what I'm doing:
|
Hi @frapontillo, can you put your code onto Plunker so I can quickly check into this issue? Many thanks! |
There you go: http://plnkr.co/edit/Pycw5R?p=preview.
I have tried to keep everything as simpler as I could by stripping out all of the unnecessary boilerplates, my app is at the very beginning but it's getting pretty complex already. Thank you very much! |
Great, thanks! 👍 |
http://plnkr.co/edit/pWysS4?p=preview Should be working now, sorry for the delayed delivery =p |
It does, thank you! |
I have a problem with two concurrently open tabs:
$localStorage.myList
$watch
ing the same object ($scope.list = $localStorage.myList
) in tab 2, the listener is triggered, but$localStorage.myList
still contains the old value!I have noticed that the
angular.element($window).bind('storage', function(event) {})
part is called in the second tab, but it never updates$storage
!Can this be fixed? I think it can by simply recreating the
$storage
starting from thelocalStorage
javascript object.The text was updated successfully, but these errors were encountered: