Hi,
In my site I have a "Like" button and when clicked it is adding 1 to that button so I will have 1 likes, 2 likes and so on. I saved the value in local storage using JSON stringify.
When I try to get the value from storage using JSON parse it is coming as a string, so when i add 1 it will add to the previous and becomes many strings like this:
9 Likes 111111 likes 11111111 likes. So i am guessing it is a string not an inetger, so how can i get the value as integer after saving it as string using stringify?
addLike(element:any){
this.likes += 1;
let data = element.textContent = this.likes + " Likes";
localStorage.setItem('numLikes',JSON.stringify(data));
}
and on ngOnInit() i have:
let data2:any = localStorage.getItem('numLikes');
this.likes = JSON.parse(data2);
this.likes = Number(this.likes);
It is giving me NaN value and nothing works!