Skip to content

Instantly share code, notes, and snippets.

@Mustafa-Omran
Created March 14, 2022 17:39
Show Gist options
  • Save Mustafa-Omran/16e70cf009b3c7c635cad1e46b81a636 to your computer and use it in GitHub Desktop.
Save Mustafa-Omran/16e70cf009b3c7c635cad1e46b81a636 to your computer and use it in GitHub Desktop.
Angular - Listen to local storage changes angular
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