Created
August 1, 2017 13:41
-
-
Save cyrilletuzi/7fae0a8728508c416d4afb68609fd163 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable, Inject, PLATFORM_ID } from '@angular/core'; | |
import { isPlatformBrowser } from '@angular/common'; | |
@Injectable() | |
export class LocalStorage { | |
constructor(@Inject(PLATFORM_ID) protected platformId: Object) {} | |
setItem(key: string, value: any) { | |
if (isPlatformBrowser(this.platformId)) { | |
localStorage.setItem(key, JSON.stringify(value)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where do I put this?