Reputation: 1
i have this function in my SpringBoot applican's controller
@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);
}
i'm trying to access it from my angular application but it doesn't work , i tried it with postman and it works just fine
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);
}
Upvotes: 0
Views: 49
Reputation: 18809
So this is the thing with Observables
. You have to subscribe
to them in order for the HTTP request to take flight.
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);
}
Upvotes: 2