-1

When creating the click event in the shopping cart, it gives an error when inserting the function parameter: "onDelete(cartItem)" I don't understand why the problem. can you help me? Thanks!

CART-COMPONENT.HTML

<button pButton pRipple type="button" label="Remove"class="p-button-danger (click)="onDelete(cartItem)" p-button-text" ></button>

CART-COMPONENT.TS

  onDelete(cartItem: CartItem) {
    this.cartService.remove(cartItem);
  }

CART.SERVICE

  remove(cartItem: CartItem) {
    const itemIndex = this.cartItems.findIndex(tempCartItem => tempCartItem.id === cartItem.id);

    if (itemIndex > -1) {
      this.cartItems.splice(itemIndex, 1);
      this.computeCartTotals();
    }
  }```




I tried to remove the parameter but the error persists.
  • What error? Please be specific. – chris Feb 14 '23 at 19:26
  • Thanks for the answer. Actually the error is: The cartItem parameter is underlined in red in the html page and it says: "The property 'cartItem' does not exist in the type 'CartDetailsComponent'. Did you mean 'cartItems'?ngtsc(2551)" – Jean Fernandine Feb 15 '23 at 00:45

1 Answers1

0

Because you are not giving us the exact error, or even whether you are getting a compile or runtime error, I can only guess:

In your template example, there are multiple syntax errors. Your double-quote characters are in all the wrong places. So this would explain compile errors. A correct version of the template might look like this:

<button pButton pRipple type="button" 
        label="Remove" class="p-button-danger" 
        (click)="onDelete(cartItem)"
        p-button-text></button>
chris
  • 2,541
  • 1
  • 23
  • 40
  • Thanks for the answer. Actually the error is as follows. The cartItem parameter is underlined in red and reads: "The 'cartItem' property does not exist on type 'CartDetailsComponent'. Did you mean 'cartItems'?ngtsc(2551)" – Jean Fernandine Feb 15 '23 at 00:41