typescript 如何从响应中获取“console.log”数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35861543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:20:19  来源:igfitidea点击:

How to 'console.log' data from response

typescriptangular

提问by sreginogemoh

I have service that return some data:

我有返回一些数据的服务:

return this._http.get(`api/data`)
    .map((response: Response) => response.json());

How can I console.log(response.json())or is there any better ways to inspect resonse?

我怎样才能console.log(response.json())或者有什么更好的方法来检查响应?

回答by Günter Z?chbauer

return this._http.get(`api/data`)
  .map((response: Response) => {
    var result = response.json();
    console.log(result);
    return result;
   });

or better

或更好

return this._http.get(`api/data`)
    .map((response: Response) => response.json())
    .do(value => console.log(value));

Ensure you have imported the operators you use.

确保您已导入您使用的运算符。