如何记录函数angular2中的内容?

时间:2016-09-01 04:12:10

标签: angular

我在服务中的函数中有以下内容:

    return this.http.get(this.heroesUrl)
        .toPromise()
        .then(response => response.json().data as Hero[])
        .catch(this.handleError);

我的问题是,我想实际注销"响应"是。当我做这样的事情时,我收到一个错误:

        return this.http.get(this.heroesUrl)
            .toPromise()
            .then(response => {
console.log(response);
response.json().data as Hero[];
})
            .catch(this.handleError);

让我看看响应中的内容的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

好像你忘记了return

  return this.http.get(this.heroesUrl)
    .toPromise()
    .then(response => {
       console.log(response);
       return response.json().data as Hero[]; <== here
    })
    .catch(this.handleError);