-1

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.

1 Answer 1

1

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));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.