0

The Angular call to a web service GET method is not working

I have created a spring boot web service. It works on the browser, but when I call it from the Angular code it does not. I have checked the URL on the browser and it works. The URL I use on the angular code is correct. On the web browser I am using http://localhost:8080/rofile/roles/find/9 on the findbyId() is also the same.


@GetMapping(value = "/find/{id}")
@ResponseBody
public RoleVO findRole(@PathVariable("id") Long id)
{
    return roleService.findById(id);
}
public findById(id: number) {
    return this.http.get(this.rolesUrl + '/find/' + id);
}

I expected the call to the web service method to go through. But it seems as if the web service call is not getting through.

1 Answers1

1

The most frequent issue again, Http uses rxjs and is observable, meaning that you should subscribe to it to make it work.

Inject the service in your component and call .subscribe()

 this.yourService.findById(id)
  .subscribe(result => {
    console.log(result );
}
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396