Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49340

How to delete the certain data from array

$
0
0

@ice174 wrote:

I am new in ionic 4. I am doing shopping cart function. I want to delete the selected item. But it delete like pop function not delete the certain item. I have follow this tutorial : https://devdactic.com/dynamic-ionic-4-slides/

In service ts I am using this function
then
Cart.page.ts

onDeleteItem(i) {
const index = this.selectedItems.indexOf(i);
if (index > -1) {
this.cartServ.deleteFromCart(index);
this.selectedItems.splice(index, 1);
console.log(this.selectedItems);
}
this.total = this.selectedItems.reduce((a, b) => a + (b.count * b.price), 0);
}

Cart.service

addToCart(product) {
    this.cartService.addProduct(product);
  }


deleteFromCart(i) {
console.log(i);
if (i === 0) {
this.cart.shift();
} else {
this.cart.splice(i, 1);
}
}

Anyone can help me?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49340

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>