[Angular] Send Data via HTTP using Angular HttpParams
Obviously in a real world application we do not only fetch data from the backend, but we also send data to be stored permanently on the server side. The HttpClient gives us different options for achieving this. In this lesson we will look at how to attach parameters to our request URL, by manually concatenating the URL by ourselves, by using the HttpParams object and also how we can send entire objects in a POSTrequest body.
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { HttpClient, HttpErrorResponse, HttpParams } from '@angular/common/http';
export interface Person {
name: string;
}
@Injectable()
export class PeopleService {
constructor(private http: HttpClient) {}
fetchPeople(): Observable<Person> {
// The same as /api/v1/people?id=2&includeName=false
const params = new HttpParams()
.set('id', '2')
.set('includeName', 'false');
return this.http
.get<Person>('/api/v1/people', {
params
});
}
}
[Angular] Send Data via HTTP using Angular HttpParams的更多相关文章
- [Angular 2 Router] Configure Your First Angular 2 Route
Using the Angular 2 router requires defining routes, passing them in to the RouterModule.forRoot and ...
- lr11 BUG?Failed to send data by channels - post message failed.
问题描述 : http协议,场景运行一会之后,报错! erro信息: Failed to send data by channels - post message failed. 解决方法 :ht ...
- 【C#】Send data between applications
This sample shows how to send data between different applications, including object data——transform ...
- 【Angular专题】——(1)Angular,孤傲的变革者
目录 一. 漫谈Angular 二. 如果你还在使用Angularjs 三. 我计划这样学习Angular技术栈 一. 漫谈Angular Angular,来自Google的前端SPA框架,与Reac ...
- [Angular] Use Angular components in AngularJS applications with Angular Elements
When migrating AngularJS (v1.x) applications to Angular you have different options. Using Angular El ...
- TCP requires two packet transfers to set up the connection before it can send data
wHTTP重用现存连接来减少TCP建立时延. HTTP The Definitive Guide 4.2.3 TCP Connection Handshake Delays When you set ...
- Caused by java.lang.Exception Failed to send data to Kafka Expiring
flink 写kafka,报错,作业挂掉 Caused by: java.lang.Exception: Failed to send data to Kafka: Expiring 89 recor ...
- Angular 从入坑到挖坑 - Angular 使用入门
一.Overview angular 入坑记录的笔记第一篇,完成开发环境的搭建,以及如何通过 angular cli 来创建第一个 angular 应用.入坑一个多星期,通过学习官方文档以及手摸手的按 ...
- [从 0 开始的 Angular 生活]No.38 实现一个 Angular Router 切换组件页面(一)
前言 今天是进入公司的第三天,为了能尽快投入项目与成为团队可用的战力,我正在努力啃官方文档学习 Angular 的知识,所以这一篇文章主要是记录我如何阅读官方文档后,实现这个非常基本的.带导航的网页应 ...
随机推荐
- 菜鸟的mongoDB学习---(六)MongoDB 索引
MongoDB 索引 ps:大概有半个月木有更新了,因为前一阶段的出差和这几天突然来的项目.导致上网时间急剧降低,实在是sorry,以后预计会好一点. 索引通常可以极大的提高查询的效率.假设没有索引. ...
- 字节与字符_字节流与字符流_ASCII与Unicode_GB2312_GBK_GB18030_BIG-5
字节(Byte):通常将可表示经常使用英文字符8位二进制称为一字节. 一个英文字母(不分大写和小写)占一个字节的空间,一个中文汉字占两个字节的空间. 符号:英文标点2占一个字节,中文标点占两个字节. ...
- 树莓派 rtl8188eu 芯片wifi驱动
总算是找到了.现拿出来分享.參考地址:https://www.raspberrypi.org/forums/viewtopic.php? p=462982#p462982 下载的地址是:https:/ ...
- 鸟哥Linux私房菜知识点总结3到5章
感觉自己对Linux的理解一直不够,所以近期翻看了一本<鸟哥的Linux私房菜>.这是一本基础的书,万丈高楼平地起,会的不多但能够学.这是我整理的一些知识点,尽管非常基础.希望和大家共同交 ...
- Linux下配置httpd服务
第一步拷贝 cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd 第二步,修改 vim /etc/rc.d/init.d/httpd # ...
- ubuntu16.04+caffe训练mnist数据集
1. caffe-master文件夹权限修改 下载的caffe源码编译的caffe-master文件夹貌似没有写入权限,输入以下命令修改: sudo chmod -R 777 ~/caffe-ma ...
- python中类的定义、实例化、封装以及私有变量/方法
1. 定义类 python中定义一个类的格式如下: class MyClass(object): def __init__(self,data1,data2): self.__data1=data1 ...
- Node.js:连接 MongoDB
ylbtech-Node.js:连接 MongoDB 1.返回顶部 1. Node.js 连接 MongoDB MongoDB是一种文档导向数据库管理系统,由C++撰写而成. 本章节我们将为大家介绍如 ...
- JPA实现一对多(OneToMany)关联
转自:https://blog.csdn.net/qq_32444825/article/details/77084580 1.考试类 @Entity public classExam impleme ...
- go并发设计模式 --资源生成器模式
1.简单的生成器 package main import ( "fmt" "math/rand" ) func GenerateIntA()chan int { ...