首页 > 解决方案 > 为什么我的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);
}

标签: javaangulartypescript

解决方案


所以这就是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);
}

推荐阅读