Created
July 6, 2017 06:24
-
-
Save alfredfrancis/a8b4d36c776302c9d86cb90723394027 to your computer and use it in GitHub Desktop.
Angular 4 - Persist & retrive variables over session
This file contains 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
persist(key,value){ | |
/* | |
* Store user information in sessionStorage | |
* @param {string} key - key name | |
* @param {json} value - value | |
* @return {} | |
*/ | |
if(typeof value == "object"){ | |
return sessionStorage.setItem(key,JSON.stringify(value)) | |
}else{ | |
return new Error("Oops! Only Objects can be persisted.") | |
} | |
} | |
retrive(key){ | |
/* | |
* Store user information in sessionStorage | |
* @param {string} key - key name | |
* @return {json} | |
*/ | |
return JSON.parse(sessionStorage.getItem(key)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment