I am experiencing an issue with using getter and setter to set a field from the web cache. When I attempt to use the setter, I encounter a TypeError
. The specific error message is:
ERROR TypeError: this.saveCache is not a function
Below are the implementation of the getter and setter functions in question:
get saveCache (): any {
if (localStorage.getItem('saveCache') === null) {
return null;
}
return JSON.parse(localStorage.getItem('saveCache'));
}
set saveCache(value:any) {
localStorage.setItem('saveCache', JSON.stringify(value));
}
Whenever I try to set the value for the saveCache
field, the error mentioned above is triggered. How can I go about resolving this issue?
An example showcasing the error can be found here:
https://stackblitz.com/edit/angular-ivy-cryfvb?file=src%2Fapp%2Fapp.component.ts