這是我回傳錯誤的 Angular 服務方法:
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}`);
}
}
這是呼叫服務方法的組件方法:
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')
})
}
我在服務方法中缺少什么?我真的沒有什么要傳入的了。我要做的就是將兩個引數傳入后端,讓 Spring Boot 完成其余的 POST。
uj5u.com熱心網友回復:
您必須為您的發布請求提供一個正文,盡管該正文可能是空的。例如,您可以這樣做:
this.http.post(`http://localhost:8080/cart/add/product/${pId}/user/${uId}`, {})
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/510216.html
上一篇:在RxJS中渲染完所有內容后從Observable中洗掉元素
下一篇:使用selenium模塊有困難
