Besides sending (or requesting) the actual data to the server API, there’s also often the need to send further metadata that helps the server to correctly interpret our request. Such data is most often sent using HTTP headers. In this lesson we learn how to leverage Angular’s HttpClient to set such headers. Note that when you have to continuously send certain application headers to the backend, for each single HTTP call that is being made, you may be better served by placing them in an HTTP interceptor.

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http'; @Injectable()
export class PeopleService { constructor(private http: HttpClient) {} fetchPeople(): Observable<Object> {
return this.http
.get('data/people.json', {
headers: new HttpHeaders().set('app-language', 'en')
});
} }

[Angular] Set Metadata in HTTP Headers with Angular HttpHeaders的更多相关文章

  1. 从Java角度理解Angular之入门篇:npm, yarn, Angular CLI

    本系列从Java程序员的角度,带大家理解前端Angular框架. 本文重点介绍Angular的开发.编译工具:npm, yarn, Angular CLI,它们就像Java在中的Maven,同时顺便介 ...

  2. Angular 个人深究(一)【Angular中的Typescript 装饰器】

    Angular 个人深究[Angular中的Typescript 装饰器] 最近进入一个新的前端项目,为了能够更好地了解Angular框架,想到要研究底层代码. 注:本人前端小白一枚,文章旨在记录自己 ...

  3. (转载)从Java角度理解Angular之入门篇:npm, yarn, Angular CLI

    本系列从Java程序员的角度,带大家理解前端Angular框架. 本文是入门篇.笔者认为亲自动手写代码做实验,是最有效最扎实的学习途径,而搭建开发环境是学习一门新技术最需要先学会的技能,是入门的前提. ...

  4. angular.module()创建、获取、注册angular中的模块

    // 传递参数不止一个,代表新建模块;空数组代表该模块不依赖其他模块 var createModule = angular.module("myModule", []); // 只 ...

  5. Angular入门,开发环境搭建,使用Angular CLI创建你的第一个Angular项目

    前言: 最近一直在使用阿里的NG-ZORRO(Angular组件库)开发公司后端的管理系统,写了一段时间的Angular以后发现对于我们.NET后端开发而言真是非常的友善.因此这篇文章主要是对这段时间 ...

  6. [Angular 2] Order Dynamic Components Inside an Angular 2 ViewContainer

    By default, when you generate components, they will simply be added to the page in order, one after ...

  7. [Angular 2] Set Properties on Dynamically Created Angular 2 Components

    When you generate Angular 2 components, you’re still able to access the component instance to set pr ...

  8. [转]angular官网 及 Ant Design of Angular

    https://angular.io/cli https://www.angular.cn/guide/quickstart https://ng.ant.design/docs/introduce/ ...

  9. [AngularJS] Angular 1.3 $submitted for Form in Angular

    AngularJS 1.3 add $submitted for form, so you can use  $submitted  to track whether the submit event ...

随机推荐

  1. POJ 2110

    终于过了,SHIT,二分+DFS即可,二分区间,根据数字是否在区间内,变成迷宫题了.枚举第一个格子,二分上界,即可. #include <iostream> #include <cs ...

  2. [GraphQL] Fetch Server Data and Client-side State in One Query using React Apollo + GraphQL

    In this lesson we look at how the Apollo @client directive can be used to fetch client-side state al ...

  3. Codeforces Round #269 (Div. 2) B. MUH and Important Things

    It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from t ...

  4. lpad&amp;rpad

    lpad( string, padded_length, [ pad_string ] ) string: 准备被填充的字符串 padded_length: 填充之后的字符串长度 pad_string ...

  5. 浅析Context Class Loader

    浅析Context Class Loader 2010-05-11 16:58:49 分类: Java 转载自 薛笛的专栏http://blog.csdn.net/kabini/archive/200 ...

  6. 数据库SQL Server2012笔记(三)——表的复杂查询

    1.数据分组--max/min/avg/sum/count select  avg(字段名),sum(字段名)  from  表名 select  count(*)  from  表名 select ...

  7. AMD cpu 下 Pytorch 多卡并行卡死问题解决

    dataparallel not working on nvidia gpus and amd cpus   https://github.com/pytorch/pytorch/issues/130 ...

  8. 对MySQL交换分区的实践

    前言 在介绍交换分区之前,我们先了解一下 mysql 分区. 数据库的分区有两种:水平分区和垂直分区.而MySQL暂时不支持垂直分区,因此接下来说的都是水平分区.水平分区即:以行为单位对表进行分区.比 ...

  9. [转]SQL Server 数据库规范

    SQL Server 数据库规范 一. 命名规范常用对象命名规范,使用帕斯卡命名法(Pascal,单词首字母大写),统一使用英文. 1. 表.英文单数名词,尽量写完整单词名称一般不超过3个英文单词都可 ...

  10. [转]C# 位域[flags]

    .NET中的枚举我们一般有两种用法,一是表示唯一的元素序列,例如一周里的各天:还有就是用来表示多种复合的状态.这个时候一般需要为枚举加上[Flags]特性标记为位域,例如: [Flags]   enu ...