Home > database >  Expected 2-3 arguments, but got 1.ts(2554) index.d.ts(2559, 23): An argument for 'body' wa
Expected 2-3 arguments, but got 1.ts(2554) index.d.ts(2559, 23): An argument for 'body' wa

Time:09-28

This is my Angular service method that returns the error:

export class CartItemService {

    constructor(private http:HttpClient) { }

    addCartItem(pId:string, uId:string) {
    return this.http.post(`http://localhost:8080/cart/add/product/${pId}/user/${uId}`);
    }
}

And here is the component method that calls the service method:

addCartItem(pId:string, uId:string) {
    this.cartItemService.addCartItem(pId,uId).subscribe({
      next:(res) => alert('cart item added'),
      error: (err) => alert('fail to add to cart')
    })
}

What am I missing in the service method? I really have nothing else to pass in. All I want to do is to pass in two parameters to the backend and let Spring Boot do the rest of the POST.

CodePudding user response:

You have to provide a body for your post request, though that body may be empty. So you could do this for example:

this.http.post(`http://localhost:8080/cart/add/product/${pId}/user/${uId}`, {})
  • Related