import { Injectable } from '@angular/core' ; @ Injectable ( { providedIn : 'root' } ) export class SessionStorageService implements Storage { public readonly length : number ; constructor ( ) { if ( typeof ( Storage ) === 'undefined' ) { throw new Error ( 'No web storage Support' ) ; } } /**
     * Empties the list associated with the object of all key/value pairs, if there are any.
     */ clear ( ) { window . sessionStorage . clear ( ) ; } /**
     * value = storage[key]
     */ getItem ( key ) { return JSON . parse ( window . sessionStorage . getItem ( key ) ) ; } /**
     * Returns the name of the nth key in the list, or null if n is greater
     * than or equal to the number of key/value pairs in the object.
     */ key ( index ) { return window . sessionStorage . key ( index ) ; } /**
     * delete storage[key]
     */ removeItem ( key ) { window . sessionStorage . removeItem ( key ) ; } /**
     * storage[key] = value
     */ setItem ( key , object ) { window . sessionStorage . setItem ( key , JSON . stringify ( object ) ) ; } }