从http post请求的响应主体中提取数据

时间:2017-06-22 16:43:10

标签: angular http

我有这个http post请求响应。

我想在不使用.map的情况下访问此响应的正文。任何帮助!

2 个答案:

答案 0 :(得分:0)

只需你可以提供这样的服务。

getResponse() {
    return this.http.get(......).map(x => x.json());
  }

然后你可以从这样的组件中获得这个响应。

this.customService.getResponse.subscribe(res => {
  console.log(res)
})

答案 1 :(得分:0)

不使用地图:

getResponse() {
    return this.http.get(......);
}

this.customService.getResponse.subscribe(res => {
  console.log(res.json())
})
  

但是,最佳做法是使用地图