java - 为什么我的http请求来自邮递员而不是来自我的角度应用程序
问题描述
我的 SpringBoot 应用程序控制器中有这个功能
@GetMapping("/cancel/{orderID}")
@ResponseStatus(HttpStatus.OK)
public void cancelOrder(@PathVariable long orderID)
{
Order order = this.orderRepository.findOrderById(orderID);
System.out.println(order);
order.setStatus(OrderStatus.CANCELLED.name());
this.orderService.cancel( order);
}
我正在尝试从我的角度应用程序中访问它,但它不起作用,我用邮递员尝试过它,它工作得很好
cancelOrder(orderId: Number) {
return this.http.get(`${this.host}/orders/cancel/${orderId}`);
}
ngOnInit(): void {
this.setCancelStatus();
}
setCancelStatus () {
this.orderID = parseInt(this.order.id);
this.ecommerceService.cancelOrder(this.orderID);
console.log(this.orderID);
}
解决方案
所以这就是Observables
. subscribe
为了使 HTTP 请求起飞,您必须对它们进行处理。
ngOnInit(): void {
this.setCancelStatus();
}
setCancelStatus () {
this.orderID = parseInt(this.order.id);
// add subscribe here.
this.ecommerceService.cancelOrder(this.orderID).subscribe(response => {
console.log(response);
});
console.log(this.orderID);
}
推荐阅读
- python - 如何避免多个线程保存到文件的权限错误
- node.js - 可以将异步函数传递给 setImmediate 以异步调用任意函数吗?
- javascript - 将相关对象合并为一个对象数组?(javascript)
- python - h2o.ai AutoML 不断重复模型对象的详细信息。如何抑制此输出?
- bash - 在bash中组合多个csv文件,将行分成不同的行
- javascript - 替换 1 个文本字段的功能词,但不适用于多个字段
- python - RNN - RuntimeError:输入必须有 3 个维度,得到 2
- php - Laravel 8 (xampp)
- kotlin - 用分隔符连接 3 个字符串
- arrays - 由于字符串存储为字符数组,那么为什么在这个问题中存储字符串而不初始化字符数组?