In development mode, items is an array but after I deploy the app, it turns into an object and I get the following error in the console:
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
In the component:
- items = [];
-
- getStorageItems(): any[] {
- try {
- return JSON.parse(localStorage.getItem('items'));
- } catch(err) {
- console.warn(err);
- return [];
- }
- }
-
- ngOnInit(): void {
- this.items = this.getStorageItems();
- }
In the HTML:
- <tr *ngFor="let item of items">
- <td>{{item.quantity}} </td>
- <td>{{item.product_name }}</td>
- </tr>