raju
raju

Reputation: 6946

angular 2 how to get returned data from .post http angular2

I am using HTTP angular2 to post some data. It is working ok, I can send data from angular2 service , receive it in my express backend.

I want to get the returned data from express. If i use .get .map((res:Response) => res.json()) works, but it is not working with .post.

This is not working::

 let successData = this._http.post(`${this.baseExpressUrl}adduser`, JSON.stringify(data), {headers:headers}).map((res:Response) => res.json());

Please help how can I subscribe in .post angular2.

Upvotes: -1

Views: 914

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 658007

There is no way to get the data outside of a callback. Move the code that depends on the response inside the callback passed to subscribe

this._http.post(`${this.baseExpressUrl}adduser`, JSON.stringify(data), {headers:headers})
.map((res:Response) => res.json())
.subscribe((data) => console.log(data));

Upvotes: 1

Related Questions