I have a single-page app in which I need to react on every change in localstorage, it looks something like:
MyComponent {
someFuncWhichIsCalledEveryTimeWhenLocalStorageChanges() {
console.log('local storage changed!');
}
funcThatChangesLocalStorage() {
localstorage.setItem('key',val);
localstorage.getItem('key')
}
}
And I've tried to use localstorage event:
window.addEventListener('storage', function(event){
...
});
but that didn't work... so I'm thinking about using Observable<>
, just don't know how to implement it properly.