Skip to content

Instantly share code, notes, and snippets.

@cyrilletuzi
Created August 1, 2017 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyrilletuzi/7fae0a8728508c416d4afb68609fd163 to your computer and use it in GitHub Desktop.
Save cyrilletuzi/7fae0a8728508c416d4afb68609fd163 to your computer and use it in GitHub Desktop.
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));
}
}
}
@chriseugenerodriguez
Copy link

where do I put this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment