read value from Response

17 views
Skip to first unread message

Paperless

unread,
Dec 5, 2016, 12:38:39 PM12/5/16
to Angular
I am trying to call HTTP GET from component on click of button

   clicked(event) {
    let commentOperation:Observable<Response>;
    commentOperation = (this.http.get(this.heroesUrl)
                  .map(this.extractData)
                  .catch(this.handleError));     
    }


//App Server side
 @RequestMapping(value = "/{resource}", method = RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE, produces=MediaType.ALL_VALUE)
public ResponseEntity getTest (@PathVariable String resource, @RequestBody Map<String, Object> id)
{
System.out.println("ResponseEntity\t"+resource+"id"+id);
ResponseEntity<String> rs = new ResponseEntity<String>("Test est"+id, HttpStatus.OK);
return rs;
}

Call is not reaching server.

How to know where it is failing in web client,
Call is not going to handlError.

If I try to console.log (commentOperation ) it prints 3 objects.
Where to look for response?

Sander Elias

unread,
Dec 6, 2016, 12:24:37 AM12/6/16
to Angular
Hi Paperless,

You need to subscribe to your observable. It only acts once there is a subscriber.

In your controller do something like this:
commentOperation
   
.subscribe(result => this.comment) // This will assign the result of the this.extractData function to this.comment.

Regards
Sander


Paperless

unread,
Dec 7, 2016, 1:57:41 PM12/7/16
to Angular
yes. This was missing. it works now.
Reply all
Reply to author
Forward
0 new messages