Advertisement
multiarts

Remove Cart

Sep 11th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Service
  2. removeFromCart(product) {
  3.     return this.getCartItems().then(result => {
  4.       if (result) {
  5.         var productIndex = result.indexOf(product);
  6.         result.splice(productIndex, 1);
  7.         return this.storage.set(CART_KEY, result);
  8.       }
  9.     })
  10.   }
  11. getCartItems() {
  12.     return this.storage.get(CART_KEY);
  13.   }
  14.  
  15. // Cart.ts
  16. removeItem(itm) {
  17.     console.log(itm);
  18.     this.cartService.removeFromCart(itm).then(() =>
  19.       this.loadCartItems()
  20.     )
  21.     if (this.cartItems.length > 0) {
  22.       this.cartItems.forEach((v) => {
  23.         this.totalAmount -= parseInt(v.totalPrice);
  24.       });
  25.       // this.isEmptyCart = true;
  26.     }
  27.   }
  28.  
  29. //cart.html
  30. <ion-card *ngFor="let itm of cartItems; let i = index">
  31. <span class="remove" (click)="removeItem(i)">
  32.  <ion-icon name="trash"></ion-icon>
  33.    {{i}}
  34.  </span>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement