Skip to content

Instantly share code, notes, and snippets.

@Dornhoth
Last active June 7, 2020 13:20
Show Gist options
  • Save Dornhoth/fedcd6f6d9c085bce5a9f36d2e4d152b to your computer and use it in GitHub Desktop.
Save Dornhoth/fedcd6f6d9c085bce5a9f36d2e4d152b to your computer and use it in GitHub Desktop.
Persistence Service directly accessing local storage
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class PersistenceService {
set(key: string, data: any): void {
localStorage.setItem(key, JSON.stringify(data));
}
get(key: string): any {
return JSON.parse(localStorage.getItem(key));
}
remove(key: string): void {
localStorage.removeItem(key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment