Angular 2: How to access an HTTP response body?

后端 未结 10 2046
南方客
南方客 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条回答
  •  再見小時候
    2020-12-13 13:03

    The response data are in JSON string form. The app must parse that string into JavaScript objects by calling response.json().

      this.http.request('http://thecatapi.com/api/images/get?format=html&results_per_page=10').
      .map(res => res.json())
      .subscribe(data => {
        console.log(data);
      })
    

    https://angular.io/docs/ts/latest/guide/server-communication.html#!#extract-data

提交回复
热议问题