Skip to content

Instantly share code, notes, and snippets.

@LironHazan
Created November 14, 2018 08:59
Show Gist options
  • Save LironHazan/e3a22a62f249038b778ffc0a234057ab to your computer and use it in GitHub Desktop.
Save LironHazan/e3a22a62f249038b778ffc0a234057ab to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class LocalStorageWrapperService {
constructor() { }
private localStorage = localStorage;
remove(key) {
return this.localStorage.removeItem(key);
}
get(key) {
try {
return JSON.parse(this.localStorage.getItem(key));
} catch (e) {
return null;
}
}
set(key, value) {
return localStorage.setItem(key, JSON.stringify(value));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment