Angular Delete Item From Cart Without reload

Discussão em 'Angular' iniciado por user2280852, Setembro 12, 2024.

  1. user2280852

    user2280852 Guest

    I have a dilemma, I'm able to delete item from database collection carts, I figured out the reason I have to reload the cart to get update on cart, this is because item is being removed from database but not from the array. I tried a number of ways to delete from array but its not working for me. I tried using splice as well as indexOf. Can someone please point me in the right direction I would greatly appreciate it. I have included a snippet of necessary code.

    CartItemComponent:

    cartitems$: Cartitems[] = []

    cartItems: CartItem [] = []


    handleRemoveFromCart(){
    alert("hit remove from cartitem");
    this.cartService.RemoveProductFromCart(this.cartItem._id).subscribe(() =>


    console.log("Product with Id deleted", this.cartItem._id

    //this.cartitems$ = this.cartitems$.splice(this.cartItem._id) does not work


    );



    }



    cartService:

    RemoveProductFromCart(_id:string){

    alert("show deleted item" + _id);
    return this.http.delete<Cartitems[]>(this.rootUrl + '/getProducts/removecartitems/' + _id);

    /* This goes back to calling function so I can try to delete from collection*/



    }

    Continue reading...

Compartilhe esta Página