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"
}
]
}

[Angular] Read Custom HTTP Headers Sent by the Server in Angular的更多相关文章

  1. Angular.JS + Require.JS + angular-async-loader 来实现异步加载 angular 模块

    传统的 angular 应用不支持异步加载模块,必须在 module 启动的时候,所有模块必须预加载进来. 通过使用 angular-async-loader 库,我们可以使用 requirejs 等 ...

  2. ASP.NET Core 2.1 Web API + Identity Server 4 + Angular 6 + Angular Material 实战小项目视频

    视频简介 ASP.NET Core Web API + Angular 6的教学视频 我是后端开发人员, 前端的Angular部分讲的比较差一些, 可以直接看代码!!!! 这是一个小项目的实战视频, ...

  3. net core 2.0 web api + Identity Server 4 + angular 5

    net core 2.0 web api + Identity Server 4 + angular 5前台使用angular 5, 后台是asp.net core 2.0 web api + ide ...

  4. [Angular] Http Custom Headers and RequestOptions

    updatePassenger(passenger: Passenger): Observable<Passenger> { let headers = new Headers({ 'Co ...

  5. [Angular] Create custom validators for formControl and formGroup

    Creating custom validators is easy, just create a class inject AbstractControl. Here is the form we ...

  6. [Angular 2] Custom Validtors

    Create a custom validtor which only accepts the string start with '123'; function skuValidator(contr ...

  7. 使用 Spring RestTemplate 调用 rest 服务时自定义请求头(custom HTTP headers)

    在 Spring 3.0 中可以通过  HttpEntity 对象自定义请求头信息,如: private static final String APPLICATION_PDF = "app ...

  8. [Angular 8] Custom Route Preloading with ngx-quicklink and Angular

    In a previous lesson we learned about implementing a custom preloading strategy. That gives you a lo ...

  9. [Angular Directive] Assign a Structual Directive a Dynamic Context in Angular 2

     Just like passing in an array to *ngFor, you can pass in any value into your structural directive s ...

随机推荐

  1. Android ViewGroup拦截触摸事件具体解释

    前言 在自己定义ViewGroup中.有时候须要实现触摸事件拦截.比方ListView下拉刷新就是典型的触摸事件拦截的样例. 触摸事件拦截就是在触摸事件被parent view拦截,而不会分发给其ch ...

  2. My SQL中show命令--MySQL中帮助查看

    My SQL中show命令--MySQL中帮助查看 学习了:http://hahaxiao.techweb.com.cn/archives/477.html 在mysql命令界面内,输入help或者? ...

  3. Android4.0设置界面改动总结(二)

    今年1月份的时候.有和大家分享给予Android4.0+系统设置的改动:Android4.0设置界面改动总结 时隔半年.回头看看那个时候的改动.事实上是有非常多问题的,比方说: ①.圆角Item会影响 ...

  4. SSM框架——具体整合教程(Spring+SpringMVC+MyBatis)

    使用SSM(Spring.SpringMVC和Mybatis)已经有三个多月了.项目在技术上已经没有什么难点了,基于现有的技术就能够实现想要的功能.当然肯定有非常多能够改进的地方.之前没有记录SSM整 ...

  5. maven+springMVC+mybatis 搭建过程

    1.创建maven web 项目 maven 创建web应用命令: mvn archetype:generate -DgroupId=[com.rom]包名 -DartifactId=[cpsrom] ...

  6. UITableView属性 自己定义UITableViewCell

    UITableView的属性全齐.供大家參考 附:http://www.bubuko.com/infodetail-561085.html //曾经在使用UITableView的时候,总是在cell上 ...

  7. 在单机上安装多个oracle实例

    1   在 hp unix上安装 oracle 10g ,这个不解释,直接安装好. 创建组oinstall,dba,用户oracle  [root@node1 ~]# groupadd oinstal ...

  8. TCP和UDP的具体区别

    TCP和UDP的最完整的区别 TCP UDP TCP与UDP基本区别: 1.基于连接与无连接 2.TCP要求系统资源较多,UDP较少: 3.UDP程序结构较简单 4.流模式(TCP)与数据报模式(UD ...

  9. IIS之虚拟目录学习

    从刚实习开始就了解到虚拟目录这个词,但是一直没去研究过什么意思,而且也没实际用过.一晃两年过去了,今天正好趁休息,补补脑学习下. 通过百度了解到,虚拟目录创建的目的是为了应对磁盘容量爆满,部署的网站不 ...

  10. localStorage、sessionStorage、cookie、session

    localStorage 和 sessionStorage HTML5 提供了两种在客户端存储数据的新方法:localStorage 和 sessionStorage: 两者都是仅在客户端(即浏览器) ...