As a beginner in Angular, I am exploring ways to retain user input and interactions on my webpage even after a refresh. After some research, I came across using local storage as a viable solution. A different answer suggested utilizing the following code snippets for setting and getting information:
Storage.prototype.setObj = function(key, obj) {
return this.setItem(key, JSON.stringify(obj))
}
Storage.prototype.getObj = function(key) {
return JSON.parse(this.getItem(key))
}
But, I still have a couple of lingering questions:
I want the data to be saved upon refresh without continuous updates, so is there a way to handle this just before a refresh event? Or would it be necessary to constantly update local storage with every change?
When should I retrieve the data? Would placing the get function in my constructor make sense for this purpose?