[Angular] Fetch non-JSON data by specifying HttpClient responseType in Angular
2024-08-25 03:01:02
By default the new Angular Http client (introduced in v4.3.1
) uses JSON as the data format for communicating with the backend API. However, there might be situations where you may want to use some other format, like text/plain
for fetching a CSV file. Using the responseType
property this can be achieved quite easily.
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.txt', { responseType: 'text'});
} }
最新文章
- Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结
- 从梯度下降到Fista
- 进程间通信--pipe
- Quartz应用实践入门案例二(基于java工程)
- JSON格式互转集合
- nginx的主要用途
- poi 导出 excel
- 在linux上安装psycopg2出错--Error: pg_config executable not found.
- 移动端 移动web屏幕适配方案 随不同宽度的屏幕而改变
- MEF 编程指南(五):延迟导出
- Javascript 知识点简介
- IOS开发-UI学习-根据URL显示图片,下载图片的练习(button,textfield,image view,url,data)
- C# WinForm调用UnityWebPlayer Control控件 <;学习笔记1>;
- POJ 3182 The Grove [DP(spfa) 射线法]
- AI繁荣下的隐忧——Google Tensorflow安全风险剖析
- Python爬虫入门教程 15-100 石家庄政民互动数据爬取
- loj#6074. 「2017 山东一轮集训 Day6」子序列(矩阵乘法 dp)
- Python系列:四、Python函数--技术流ken
- TableView刷新跳动问题
- Spring.之.jar包官网下载