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. crm使用soap批量删除数据

    //批量删除数据 function demo() {     //实体名称     var entityname = "fw_student";     var data = [] ...

  2. Window7幻灯片字体显示混乱,难道真的是病毒么

    这个问题有几天了.就是在其它人的PowerPoint2010做的ppt文件.发到这台有问题的电脑上(PowerPoint2007)就会显示全然不一样.例如以下所看到的. watermark/2/tex ...

  3. 程序猿爱情表白专用html5动画网页的代码

    程序猿爱情表白专用html5动画网页的代码 下载地址:源代码 程序员表白专用的html5动画特效网页,真的挺羡慕创作者的水平,有这水平能够把爱表白给想表白的人,不要以为那些鲜花是用 的图片.你会发如今 ...

  4. ClassNotFoundException和NoClassDefFoundError的差别

    正如它们的名字所说明的:NoClassDefFoundError是一个错误(Error),而ClassNOtFoundException是一个异常,在Java中错误和异常是有差别的,我们能够从异常中恢 ...

  5. 使用roslyn编译website项目

    在Nuget中,添加Microsoft.CodeDom.Providers.DotNetCompilerPlatform. 在添加这个dll的时候,会自动在web.config中添加以下内容 < ...

  6. Redis学习笔记(十) 命令进阶:事务操作

    原文链接:http://doc.redisfans.com/transaction/index.html Redis中也提供了对于事务的支持,由于Redis是单线程处理Client的请求,所以实现起来 ...

  7. Spark SQL概念学习系列之性能调优

    不多说,直接上干货! 性能调优 Caching Data In Memory Spark SQL可以通过调用sqlContext.cacheTable("tableName") 或 ...

  8. Core篇——初探依赖注入

    目录 1.DI&&IOC简单介绍 2.UML类图中六种关联关系 3..net core 中DI的使用 4..net core DI初始化源码初窥 DI&&IOC简单介绍 ...

  9. Data type-数据类型

    操作方式.含义.存储方式. In computer science and computer programming, a data type or simply type is a classifi ...

  10. CDR实例教程-高考789,敢拼就能赢!

    本教程是我去年做的一个案例,本来今年想要在做一个,突然意识到今天就是高考日了,没来的及,所以大家将就看些.7.8.9是值得一生纪念的日子,也是以后的每年都会怀念的日子,因为是全国都在上演史诗大剧“决战 ...