I currently have an array of objects representing items. These items are fetched from a service and displayed on the cart page.
When I click on the remove button, I execute the delete this.cart.items[i];
function. The item is successfully removed from the service object, but a blank element appears on the page along with console errors stating
Cannot read property 'qty' of undefined
. I assumed that ngfor would automatically update the DOM to remove the element when the object is deleted. Do I need to manually remove the element from the DOM as well?
In the example array provided below, my goal is to completely remove the first item while still displaying the second item.
[
{
"desc": "Description",
"item": "item 1",
"id": "1",
"portion": "small",
"price": "4.25",
"qty": 3
},
{
"desc": "Description",
"item": "item 2",
"id": "2",
"portion": "large",
"price": "4",
"qty": 1
}
]
<div class="cart-item" *ngFor="let item of items" (click)='ontap(item);'>
{{ x.item }}
</div>
This is where I am displaying the items, however the element with no data is still visible. Any suggestions on how to resolve this issue would be appreciated. Thank you.