import { Injectable } from '@angular/core' ; const ls = sessionStorage ; @ Injectable ( ) export class SessionStorageService { constructor ( ) { } public get < T > ( key ) { return JSON . parse ( ls . getItem ( key ) ) as T ; } public getList < T > ( key ) { const before = ls . getItem ( key ) ; return before ? ( JSON . parse ( before ) as T [ ] ) : [ ] ; } public set ( key , value ) { if ( ! value && value === undefined ) { return ; } const arr = JSON . stringify ( value ) ; ls . setItem ( key , arr ) ; } public clearAll ( ) { ls . clear ( ) ; } public remove ( key ) { ls . removeItem ( key ) ; } }