I get the error
this.items.push is not a function
From googling I’ve found out that this means that items is not an array. I’ve tried to account for this by checking if it’s undefined and using this.items = this.items || ; I also tried to change data and make it an array but when I enclose data in square brackets, nothing gets pushed to items.
It’s very hard to troubleshoot because the error only shows up in the developer console after I’ve deployed it. No errors show up in the developer console when I am in development mode.
items = [];
storageKey = 'MyDataStorageKey';
public onSubmit(thumbnail, quantity, product_name, product_price){
var data = {
thumbnail,
quantity,
product_name,
product_price
};
this.items = this.items || [];
if (typeof this.items !== 'undefined')
this.items.push(data);
localStorage.setItem(this.storageKey, JSON.stringify(this.items));
this.isSubmitted = true;
}
ngOnInit(): void {
this.items = this.getStorageItems();
}
I also get the error: Cannot find a differ supporting object ‘[object Object]’ of type ‘object’. NgFor only supports binding to Iterables such as Arrays. I get the error for the following:
<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>
</tr>