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. hive join 优化 --小表join大表

    1.小.大表 join 在小表和大表进行join时,将小表放在前边,效率会高.hive会将小表进行缓存. 2.mapjoin 使用mapjoin将小表放入内存,在map端和大表逐一匹配.从而省去red ...

  2. ym——物联网入口之中的一个Android蓝牙4.0

    转载请注明本文出自Cym的博客(http://blog.csdn.net/cym492224103),谢谢支持! 假设还有同学不知道蓝牙4.0能够做什么请查看Android+蓝牙 4.0 将带来什么? ...

  3. 【简单的案例分享,停机10分钟】10204升级CRS&amp;DB的PSU至102044

    发现一个现象,AIX5.3+HACMP+10.2.0.4RAC+RAW的环境,执行五六年的数据库crsd.log都会报下面错误: ----------------------------------- ...

  4. phpmyadmin客户端多服务器配置

    修改libraries/config.default.php 545行,添加 $cfg['Servers']['2'] = $cfg['Servers'][$i];$cfg['Servers']['2 ...

  5. 最简单的启动并连接一个redis的docker容器

    启动一个容器: $ sudo docker run --name <name> -d redis 连接一个容器: sudo docker run -it --link <name&g ...

  6. Jq自定义的方法绑定树结构

    1.先上效果图  (借鉴博客) 2.这边不做样式的只做结构 function toTreeData(data) { var pos = {}; var tree = []; var i = 0; wh ...

  7. ASP.NET中各种缓存技术的特点及使用场景

    对于一些不经常改变却经常被request的数据,我们喜欢将它们缓存在内存.这样用户请求时先到缓存中去取,如果缓存中没有,再去数据库拿,提高响应速度.缓存一般实现在BLL,这样可以与DAL分离,更换数据 ...

  8. 关于Java中equal函数和==的一些区别

    equal函数比较的到底是什么,很明显是比较的值,但是什么值?与==比较的堆中的内存地址不同,其比较的是对象的值,包括各个属性的值.我们在重新overriding此方法时首先要判断是否为同一对象,如果 ...

  9. DirectUI界面编程(四)界面布局详解

    Duilib的界面布局使用xml文件进行描述,在Duilib v1.1版本的xml布局文件中我们可以使用以下这些标签(后续版本标签有扩充): 这些标签总的来讲可以分为三类: 窗口类,该类别中只有一个W ...

  10. mysql中间件研究(tddl atlas cobar sharding-jdbc)

    mysql-proxy是官方提供的mysql中间件产品可以实现负载平衡,读写分离,failover等,但其不支持大数据量的分库分表且性能较差.下面介绍几款能代替其的mysql开源中间件产品,Atlas ...