angular 6 or 7: How to import RequestOptions and ResponseContentType in '@angular/common/http'

荒凉一梦 提交于 2019-11-29 14:39:54

问题


I have migrated angular 4 code to angular 6 and I want to know how to import below code in angular 6 or 7?

import { RequestOptions, ResponseContentType } from '@angular/common/http';

回答1:


Pass this way ...

import { HttpClient, HttpHeaders } from '@angular/common/http';

 let headers = new HttpHeaders({
    'Content-Type': 'application/json'
 });
 let options = {
    headers: headers
 }

 this.http.post(URL, param, options)
    .subscribe(data => {
         console.log(data);
 });



 // For pass blob in API 

 return this.http.get(url, { headers: new HttpHeaders({
   'Authorization': '{data}',
   'Content-Type': 'application/json',
 }), responseType: 'blob'}).pipe (
 tap (
     // Log the result or error
     data => console.log('You received data'),
     error => console.log(error)
  )
);


来源:https://stackoverflow.com/questions/53118316/angular-6-or-7-how-to-import-requestoptions-and-responsecontenttype-in-angula

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!