By default the response body doesn’t contain all the data that might be needed in your app. Your server might return some special header which you have to read explicitly. In such case we can use the { observe: ‘response’} configuration of the Angular HttpClient. Let’s explore how.

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { HttpClient, HttpResponse } from '@angular/common/http'; export interface Person {
name: string;
} @Injectable()
export class PeopleService { constructor(private http: HttpClient) {} fetchPeople(): Observable<HttpResponse<Person>> {
return this.http
.get<Person>('data/people.json', { observe: 'response'});
}
}

Now instead of just returning your data, it returns your response object.

 {
"headers": {
"normalizedNames": [],
"lazyUpdate": null
},
"status": 200,
"statusText": "OK",
"url": "https://run.plnkr.co/preview/cjdn2x8fh000ffillqi8d3o4k/data/people.json",
"ok": true,
"type": 4,
"body": [
{
"name": "xxx"
},
{
"name": "xxx"
}
]
}

最新文章

  1. [LeetCode] Implement Trie (Prefix Tree)
  2. oracle sqlplus 格式化输出
  3. @weakify, @strongify ObjC的Block中使用weakSelf/strongSelf @weakify/@strongify
  4. (原)java中对象复制、==、equals
  5. Intent的七大属性
  6. 分布式架构高可用架构篇_01_zookeeper集群的安装、配置、高可用测试
  7. 【IOS】2.基础
  8. 开源项目:网页实时通信WebRTC
  9. jdbc内容
  10. java改变图片文件尺寸
  11. ios 视频/图片压缩
  12. springMVC源码分析--AbstractHandlerMethodMapping获取url和HandlerMethod对应关系(十)
  13. 实用的几个JS新特性(es 2016)
  14. POJ2728 Desert King
  15. list集合去除重复对象的实现
  16. Sql server bulk insert
  17. Thinkphp5笔记六:公共模块common的使用
  18. 安卓秘钥生成命令以及SHA1值获取办法
  19. javascript面向对象的程序设计之Object.getOwnPropertyDescriptor()
  20. 团队博客作业Week2 --- 学长学姐访谈录

热门文章

  1. 【基础训练】HDOJ2032杨辉三角
  2. PECL轻松安装PHP扩展
  3. C#创建PDF文档
  4. ubuntu解压命令全览(rar)
  5. SYN-Flood防御方法之一Synproxy
  6. Java语言的优点
  7. 限制textfield的文字长度
  8. 异步编程(二)基于事件的异步编程模式 (EAP)
  9. php方法-------将汉字转为拼音或者提取汉字首字母
  10. Unity脚本生命周期 图解