Created
March 14, 2022 17:39
-
-
Save Mustafa-Omran/16e70cf009b3c7c635cad1e46b81a636 to your computer and use it in GitHub Desktop.
Angular - Listen to local storage changes angular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, HostListener, OnInit } from '@angular/core'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'] | |
}) | |
export class AppComponent { | |
@HostListener('window:storage', ['$event']) | |
onStorageChange(event: StorageEvent) { | |
// local storage key | |
if (event.key === 'TOKEN') { | |
window.location.reload(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hol HOL