import { isPlatformServer } from '@angular/common' ; import { Inject , Injectable , PLATFORM_ID } from '@angular/core' ; @ Injectable ( ) export class Storage { constructor ( @ Inject ( PLATFORM_ID ) private platformId ) { } static _ ( platformId ) { return new Storage ( platformId ) ; } get ( key ) { if ( isPlatformServer ( this . platformId ) ) return null ; try { return window . localStorage . getItem ( key ) ; } catch ( err ) { console . log ( err ) ; return null ; } } set ( key , value ) { if ( isPlatformServer ( this . platformId ) ) return ; return window . localStorage . setItem ( key , value ) ; } destroy ( key ) { if ( isPlatformServer ( this . platformId ) ) return ; return window . localStorage . removeItem ( key ) ; } clear ( ) { if ( isPlatformServer ( this . platformId ) ) return ; window . localStorage . clear ( ) ; } }