首页 > Web开发 > 详细

[Angular] Fetch non-JSON data by specifying HttpClient responseType in Angular

时间:2018-02-14 21:28:03      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:ica   service   ext   esp   4.3   ttpClient   cto   sin   post   

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

标签:ica   service   ext   esp   4.3   ttpClient   cto   sin   post   

原文:https://www.cnblogs.com/Answer1215/p/8448902.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号