import { Injectable } from '@angular/core' ; import { ILogger } from '../../types/logger-type' ; import { LoggerService } from '../logger/logger.service' ; @ Injectable ( { providedIn : 'root' } ) export class StorageService { public storage = window . localStorage ; public log : ILogger ; constructor ( private loggerSrv ) { this . log = this . loggerSrv . get ( 'StorageService' ) ; } public set ( key , item ) { const value = JSON . stringify ( { item : item } ) ; this . storage . setItem ( key , value ) ; } public get ( key ) { const value = JSON . parse ( this . storage . getItem ( key ) ) ; return value ?. item ? value . item : null ; } public clear ( ) { this . log . d ( 'Clearing localStorage' ) ; this . storage . clear ( ) ; } }