I am trying to set the items array and push to localStorage with the following code:
public onSubmit(thumbnail, quantity, product_name, product_price){
const data = {
thumbnail,
quantity,
product_name,
product_price
};
localStorage.setItem(this.items, JSON.stringify(data));
this.items.push(JSON.parse(localStorage.getItem(data)));
}
I get the following errors:
Argument of type ‘any’ is not assignable to parameter of type ‘string’.
for localStorage.setItem(this.items, JSON.stringify(data));
Argument of type ‘{ thumbnail: any; quantity: any; product_name: any; product_price: any; }’ is not assignable to parameter of type ‘string’.
for this.items.push(JSON.parse(localStorage.getItem(data)));
In my HTML:
<tr *ngFor="let item of items;">
<td>
<td><img src="../assets/images/gallery/{{item.thumbnail}}" /></td>
<td>{{item.quantity}} </td>
<td>{{item.product_name }}</td>
<td>{{item.product_price}} </td>
<td>{{item.quantity * item.product_price }}</td>
</tr>