addToCart (event: any) {
if ("cart" in localStorage) {
this.cartProducts = JSON.parse(localStorage.getItem("cart")!)
console.log(event);
let exist = this.cartProducts.find(item => item.item.id == event.item.id);
if(exist) {
alert("This product is already in your cart");
} else {
this.cartProducts.push(event);
localStorage.setItem("cart" , JSON.stringify(this.cartProducts));
}
}else {
this.cartProducts.push(event);
localStorage.setItem("cart" , JSON.stringify(this.cartProducts));
}
}
your text
I tried to solve it with type annotation but I couldn't. And there is no any quick fix to fix this problem.