[Angular] Fetch non-JSON data by specifying HttpClient responseType in Angular
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'});
- }
- }
[Angular] Fetch non-JSON data by specifying HttpClient responseType in Angular的更多相关文章
- 使用 angular directive 和 json 数据 D3 随着标签 donut chart演示样本
使用angular resource载入中priorityData.json中间json数据,结合D3绘制甜甜圈图.执行index.html其结果见于图.: priorityData.json中jso ...
- fetch发送Form Data请求并携带cookie
今天我们来说说如何fetch发送Form Data请求并携带cookie,直接进入正题好吧,别问我今天为啥不在开始吹两句了,累到一句牛逼不想吹...... 步骤1: 设置头部,"Conten ...
- fetch获取json的正确姿势
fetch要求参数传递,遇到请求无法正常获取数据,网上其他很多版本类似这样: fetch(url ,{ method: 'POST', headers:{ 'Accept': 'application ...
- react之fetch请求json数据
Fetch下载 npm install whatwg-fetch -S Fetch请求json数据 json文件要放在public内部才能被检索到
- [Svelte 3] Use an onMount lifecycle method to fetch and render data in Svelte 3
Every Svelte component has a lifecycle that starts when it is created, and ends when it is destroyed ...
- directly receive json data from javascript in mvc
if you send json data to mvc,how can you receive them and parse them more simply? you can do it like ...
- Google Volley: How to send a POST request with Json data?
sonObjectRequest actuallyaccepts JSONObject as body. From http://arnab.ch/blog/2013/08/asynchronous- ...
- Guzzle Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, malformed JSON
项目更新到正式平台时,出现Guzzle(5.3) client get请求出现:Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, ...
- SQL to JSON Data Modeling with Hackolade
Review: SQL to JSON data modeling First, let’s review, the main way to represent relations in a rela ...
随机推荐
- Linux下I/O复用 Select与Poll
Select #include <sys/time.h>#include <sys/types.h>#include <sys/unistd.h> int sele ...
- HDU 4196
很容易由算术基本定理知道,完全平方数就是所有质因子指数为偶数的数.而求得N以下的质因子,可由前两篇的公式知,由N!与p的关系求得.对于指数为p的,用N!除去就可以,因为p必定属于N以内,且无重复. 至 ...
- POJ 1284
想了很久,只想到枚举的方法,估计会超时吧. 原来有这样一条性质:p为素数,则p有phi(p-1)个原根 Orz... #include <iostream> #include <cs ...
- C语言实现使用动态数组实现循环队列
我在上一篇博客<C语言实现使用静态数组实现循环队列>中实现了使用静态数组来模拟队列的操作. 因为数组的大小已经被指定.无法动态的扩展. 所以在这篇博客中,我换成动态数组来实现. 动态数组能 ...
- 数据可视化利器pyechart和matplotlib比较
python中用作数据可视化的工具有多种,其中matplotlib最为基础.故在工具选择上,图形美观之外,操作方便即上乘. 本文着重说明常见图表用基础版matplotlib和改良版pyecharts作 ...
- 【cocos2d-js官方文档】二十、moduleConfig.json
概述 该配置文件相当于v2版本号中的jsloader.js. 改造的目的是为了使得配置纯粹化,同一时候也能比較好的支持cocos-console.cocos-utils甚至是用户自己定义脚本工具. 字 ...
- nodejs免费空间
https://www.nitrous.io/join/N_aIGoSnOMI node免费空间,可以把自己node 代码部署到云端. 也可以在线编辑,当然也能在外网地址访问到,是自己学习nodejs ...
- linux + nginx 的配置优化
linux 关于TCP/IP 的优化配置 配置文件/etc/sysctl.conf 修改完文件生效的命令 /sbin/sysctl -p 如下是总结的配置内容及说明 net.ipv4.con ...
- oracle 优化之组合索引
组合索引适用场景: 1.适用在单独查询返回记录很多,组合查询后忽然返回记录很少的情况: 比如where 学历=硕士以上 返回不少的记录 比如where 职业=收银员 同样返回不少的记录 于是无论哪个条 ...
- tomcat配置一个服务监听两个端口
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" ...