Last active
June 7, 2020 13:20
-
-
Save Dornhoth/fedcd6f6d9c085bce5a9f36d2e4d152b to your computer and use it in GitHub Desktop.
Persistence Service directly accessing local storage
This file contains hidden or 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 } 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