src/client/app/modules/core/services/storage.service.ts
Methods |
getItem |
getItem(key: StorageKey)
|
Returns :
any
|
removeItem |
removeItem(key: StorageKey)
|
Returns :
void
|
setItem |
setItem(key: StorageKey, value: any)
|
Returns :
void
|
import { Injectable } from '@angular/core';
import { IStorage, StorageKey } from '../interfaces/istorage';
@Injectable()
export class StorageService implements IStorage {
setItem(key: StorageKey, value: any): void {
localStorage.setItem('' + key, value === null ? null : JSON.stringify(value));
}
getItem(key: StorageKey): any {
const value = localStorage.getItem('' + key);
return value === null ? null : JSON.parse(value);
}
removeItem(key: StorageKey): void {
localStorage.removeItem('' + key);
}
}