Skip to content

Instantly share code, notes, and snippets.

@khalidsheet
Created September 1, 2019 21:55
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 khalidsheet/dc6017a32acfa31c5d90b638652f3625 to your computer and use it in GitHub Desktop.
Save khalidsheet/dc6017a32acfa31c5d90b638652f3625 to your computer and use it in GitHub Desktop.
Simple Session Manager Service in angular
import { Injectable } from "@angular/core";
@Injectable({
providedIn: "root"
})
export class SessionManagerService {
constructor() {}
set(key: string, value: any): SessionManagerService {
if (value instanceof Object) {
value = JSON.stringify(value);
}
localStorage.setItem(key, value);
return this;
}
get(key: string): string {
return localStorage.getItem(key);
}
forget(key: string): void {
localStorage.removeItem(key);
}
destroy(): void {
localStorage.clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment