chore: copia de libs/shared con prefijo Pi y APIs de terceros actualizadas
This commit is contained in:
26
libs/ui/src/lib/util/local-storage/local-storage.service.ts
Normal file
26
libs/ui/src/lib/util/local-storage/local-storage.service.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
// Angular
|
||||
import { isPlatformBrowser } from '@angular/common';
|
||||
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class LocalStorageService {
|
||||
constructor(@Inject(PLATFORM_ID) public platformId: Object) {}
|
||||
|
||||
getItem(tag: string) {
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
const value = (window as any).localStorage.getItem(tag);
|
||||
if (value) return JSON.parse(value);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
setItem(tag: string, value: any) {
|
||||
if (isPlatformBrowser(this.platformId))
|
||||
(window as Window).localStorage.setItem(tag, JSON.stringify(value));
|
||||
}
|
||||
|
||||
deleteItem(tag: string) {
|
||||
if (isPlatformBrowser(this.platformId))
|
||||
(window as Window).localStorage.removeItem(tag);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user