"across tab localstorage" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "across tab localstorage" answered properly. Developers are finding an appropriate answer about across tab localstorage related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like across tab localstorage. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on across tab localstorage.
across tab localstorage
import { Injectable, OnDestroy } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { share } from 'rxjs/operators';
@Injectable()
export class StorageService implements OnDestroy {
private onSubject = new Subject<{ key: string, value: any }>();
public changes = this.onSubject.asObservable().pipe(share());
constructor() {
this.start();
}
ngOnDestroy() {
this.stop();
}
public getStorage() {
let s = [];
for (let i = 0; i < localStorage.length; i++) {
s.push({
key: localStorage.key(i),
value: JSON.parse(localStorage.getItem(localStorage.key(i)))
});
}
return s;
}
public store(key: string, data: any): void {
localStorage.setItem(key, JSON.stringify(data));
this.onSubject.next({ key: key, value: data})
}
public clear(key) {
localStorage.removeItem(key);
this.onSubject.next({ key: key, value: null });
}
private start(): void {
window.addEventListener("storage", this.storageEventListener.bind(this));
}
private storageEventListener(event: StorageEvent) {
if (event.storageArea == localStorage) {
let v;
try { v = JSON.parse(event.newValue); }
catch (e) { v = event.newValue; }
this.onSubject.next({ key: event.key, value: v });
}
}
private stop(): void {
window.removeEventListener("storage", this.storageEventListener.bind(this));
this.onSubject.complete();
}
}
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on across tab localstorage can get a collection of related answers to their query. Programmers need to enter their query on across tab localstorage related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about across tab localstorage for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of across tab localstorage while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "across tab localstorage". Visit this developer's friendly online web community, CodeProZone, and get your queries like across tab localstorage resolved professionally and stay updated to the latest Whatever updates.