Angular 2: How to access an HTTP response body?

后端 未结 10 2040
南方客
南方客 2020-12-13 12:25

I wrote the following code in Angular 2:

this.http.request(\'http://thecatapi.com/api/images/get?format=html&results_per_page=10\').
      subscribe((re         


        
10条回答
  •  Happy的楠姐
    2020-12-13 13:20

    I had the same issue too and this worked for me try:

    this.http.request('http://thecatapi.com/api/images/get?format=html&results_per_page=10').
      subscribe((res) => {
        let resSTR = JSON.stringify(res);
        let resJSON = JSON.parse(resStr);
        console.log(resJSON._body);
      })
    

提交回复
热议问题