Is there a way to ensure that when the "add to favorites" button is clicked, its data is stored in localStorage only once? If it already exists in localStorage, clicking for a second time should not have any effect except showing an alert message.
I would like to achieve this functionality in Angular Ionic. Any suggestions on how to implement this?
Here is a link to my working application and sample code:
https://github.com/Novian227/WeatherAppIonic
save() {
let data = [];
let w = JSON.parse(localStorage.getItem('fav'));
if (w != null) {
for (let i=0; i<w.length; i++) {
data.push(w[i]);
}
}
data.push(this.weather);
localStorage.setItem('fav', JSON.stringify(data));
}