Angular 2: How to access an HTTP response body?

后端 未结 10 2063
南方客
南方客 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条回答
  •  猫巷女王i
    2020-12-13 13:09

    Can't you just refer to the _body object directly? Apparently it doesn't return any errors if used this way.

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

    Working plunker

提交回复
热议问题