[Angular] Send Data via HTTP using Angular HttpParams
2023-09-14 08:59:17 时间
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 POST
request 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 开发人员对腾讯 Cloud Studio 使用后的体验报告
- Go HTTP 编程 | 01 - 使用 http 包创建 Web 服务器
- HTTP默认端口_http协议使用的端口号
- 关于 Angular HTTP Interceptor 中 Request 和 Response 的 immutable 特性
- angular 路由懒加载_angular路由
- angular框架发展史
- 【Angular教程】自定义管道
- Angular Feature Modules
- Angular 应用如何回退到之前曾经浏览过的页面
- 关于 Angular 开发时对主流浏览器支持的话题
- Angular 项目多国语言设置
- 部署Linux服务器,实现高效安全的HTTP通信(http服务器linux)
- 服务Linux快速启动HTTP服务实现网络分享(linux启动http)
- 端口Linux查看HTTP端口:一步一步指南(linux查看http)
- 请求使用Linux发送HTTP请求的方法(linux发送http)
- Linux下抓取HTTP包的技术实现(linux抓http包)
- Linux快速搭建超强HTTP服务器(linux搭建http服务器)
- 熟悉Redis,HTTP抓包,防止网络安全漏洞(redis,http抓包)
- 高质量 VR 直播有望了,Google 带来 Equi-Angular Cubemaps 技术