Working on an Angular project, I am attempting to remove an object from an array. To achieve this, I need to filter the array and then update the storage (specifically, capacitor/storage) with the modified array.
Here is my function:
deleteArticle(id: string): void {
this.order = this.order[0].filter(p => p.products.productKey !== id);
}
order: Order; ==>
export interface OrderProduct {
productKey: string;
productName: string;
price: number;
}
export interface Order {
key?: string;
customerKey: string;
products: OrderProduct[];
country?: string;
city?: string;
postcode?: string;
addressLine?: string;
creationDate?: any; //date
}
When the button is clicked in the HTML:
<ion-col>
<ion-button (click)="deleteArticle(p.productKey)">
<ion-icon name="trash-outline"></ion-icon>
</ion-button>
</ion-col>
After clicking the button, the array looks as expected, with the correct ID for filtering. However, an error keeps occurring:
Cannot read properties of undefined (reading 'filter')