[Angular] Read Custom HTTP Headers Sent by the Server in Angular
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的更多相关文章
- Angular.JS + Require.JS + angular-async-loader 来实现异步加载 angular 模块
传统的 angular 应用不支持异步加载模块,必须在 module 启动的时候,所有模块必须预加载进来. 通过使用 angular-async-loader 库,我们可以使用 requirejs 等 ...
- ASP.NET Core 2.1 Web API + Identity Server 4 + Angular 6 + Angular Material 实战小项目视频
视频简介 ASP.NET Core Web API + Angular 6的教学视频 我是后端开发人员, 前端的Angular部分讲的比较差一些, 可以直接看代码!!!! 这是一个小项目的实战视频, ...
- 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 ...
- [Angular] Http Custom Headers and RequestOptions
updatePassenger(passenger: Passenger): Observable<Passenger> { let headers = new Headers({ 'Co ...
- [Angular] Create custom validators for formControl and formGroup
Creating custom validators is easy, just create a class inject AbstractControl. Here is the form we ...
- [Angular 2] Custom Validtors
Create a custom validtor which only accepts the string start with '123'; function skuValidator(contr ...
- 使用 Spring RestTemplate 调用 rest 服务时自定义请求头(custom HTTP headers)
在 Spring 3.0 中可以通过 HttpEntity 对象自定义请求头信息,如: private static final String APPLICATION_PDF = "app ...
- [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 ...
- [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 ...
随机推荐
- Python学习笔记-小记
1.字符串string 推断一个字符(char)是数字还是字母 str.isalpha() #推断是否为字母 str.isdigit() #推断是否为数字 推断一个字符串是否为空 if not str ...
- Class example in C/C++
class Player { private: int health; //these are the attributes int strength; int agility; pu ...
- 基于servlet实现一个web框架
servlet作为一个web规范.其本身就算做一个web开发框架,可是其web action (响应某个URI的实现)的实现都是基于类的,不是非常方便,而且3.0之前的版本号还必须通过web.xml配 ...
- 关于Win 10的隐私保护政策
近日.有人责备Win10收集用户信息,事实上这样的指责并不公平,比方:"Privacy Groups Claim Microsoft Uses Windows 10 as Big Broth ...
- oracle故障处理之删除大表空间hang住
背景 数据库分区表数据越来越大,需要对过期话的数据进行迁移,以及大的分区表需要进行数据的清理和删除,达到释放磁盘空间的目的. 问题说明 环境:linux 6.X 数据库:oracle 11.2.0.4 ...
- 初涉springboot
1.首先,我们需要了解微服务是什么? 微服务 (Microservices) 是一种软件架构风格,它是以专注于单一责任与功能的小型功能区块 (Small Building Blocks) 为基础,利用 ...
- Flask_URL和视图
1.Flask_URL和视图 1.1.第一个flask程序 from flask import Flask #创建一个Flask对象,传递__name__参数进去 app = Flask(__na ...
- node-express项目的搭建并通过mongoose操作MongoDB实现增删改查分页排序(四)
最近写了一个用node来操作MongoDB完成增.删.改.查.排序.分页功能的示例,并且已经放在了服务器上地址:http://39.105.32.180:3333. Mongoose是在node.js ...
- 洛谷P4016 负载平衡问题(最小费用最大流)
题目描述 GG 公司有 nn 个沿铁路运输线环形排列的仓库,每个仓库存储的货物数量不等.如何用最少搬运量可以使 nn 个仓库的库存数量相同.搬运货物时,只能在相邻的仓库之间搬运. 输入输出格式 输入格 ...
- es6总结(二)
1.es6三种声明方式: a.var 全局声明 b.let 局部变量声明 c.const 常量声明 2.变量的解构赋值 a.数组的解构赋值 等号左边与右边形式统一 let [a,[b,c] ...