Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Service
- removeFromCart(product) {
- return this.getCartItems().then(result => {
- if (result) {
- var productIndex = result.indexOf(product);
- result.splice(productIndex, 1);
- return this.storage.set(CART_KEY, result);
- }
- })
- }
- getCartItems() {
- return this.storage.get(CART_KEY);
- }
- // Cart.ts
- removeItem(itm) {
- console.log(itm);
- this.cartService.removeFromCart(itm).then(() =>
- this.loadCartItems()
- )
- if (this.cartItems.length > 0) {
- this.cartItems.forEach((v) => {
- this.totalAmount -= parseInt(v.totalPrice);
- });
- // this.isEmptyCart = true;
- }
- }
- //cart.html
- <ion-card *ngFor="let itm of cartItems; let i = index">
- <span class="remove" (click)="removeItem(i)">
- <ion-icon name="trash"></ion-icon>
- {{i}}
- </span>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement