Issue
I want to delete or destroy my localStorage content whenever I route to a different component. I want to achieve this so as to avoid the localStorage variable from storing previous values even tho new values are coming in.
Am I on the right path?
Game Component
export class Game implements OnDestroy{
constructor(){
this.currentGame = JSON.parse(localStorage.getItem('currentGame'));
}
ngOnDestroy(){
this.currentGame = null;
}
}
Solution
you can use
localStorage.removeItem('currentGame');
Alternatively, you can also clear the whole localStorage with
localStorage.clear();
Answered By - Deblaton Jean-Philippe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.