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 store(key: string, data: any): void {
localStorage.setItem(key, JSON.stringify(data));
this.onSubject.next({ key: key, value: data})
}
I am using storageService to store localStorage like -
if(this.jsp_url){
this.storageService.store('jsp_isTagEnabled', true);
this.storageService.store('jsp_dmReload', true);
}else{
this.storageService.store('isTagEnabled', true);
this.storageService.store('dmReload', true);
}
i am adding jsp_ statically based on condition, for now, how can i add it dynamically.