As you haven't posted proper answer without showing your imports firstly please have a look at here
Now make sure you have imported all required dependencies for making http request. now you can use this code as shared_service
getRoom(id) {
let headers = new Headers();
headers.append("Content-Type", 'application/json'); // header portion ends here
let body = JSON.stringify({id}); // body ends here
let options = new RequestOptions({
method: RequestMethod.Post,
url: '/api/forum/findRoom',
headers: headers,
body: body
})
return this.http.request(new Request(options))
.map((res: Response) => {
if (res) {
return [{ status: res.status, json: res.json() }]
}
});
};
Now this will create your shared service for making post request. now whenever you required to take data(response) in the controller (class). than you just need to import this file and call the method named getRoom()
using class name as prefix. and then subscribe there to get data like this :-
class_name.getRoom('your_data')
.subscribe((data) => { console.log(data);}, <------subscribe to the service
err=>console.log(err),
()=>console.log('done'));
I hope this clears everything related to Http. if you have any query comment here.
also to get Request using http see here
Working Example of Http