【问题标题】:angular 6 or 7: How to import RequestOptions and ResponseContentType in '@angular/common/http'角度 6 或 7:如何在“@angular/common/http”中导入 RequestOptions 和 ResponseContentType
【发布时间】:2019-04-06 16:23:39
【问题描述】:

我已将 angular 4 代码迁移到 angular 6,我想知道如何在 angular 6 或 7 中导入以下代码?

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

【问题讨论】:

    标签: angular angular6 angular7


    【解决方案1】:

    从这里过去……

    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)
      )
    );
    

    【讨论】:

    • 我要使用 ResponseContentType.Blob
    • @AmolBLande 我已经更新了我的答案,请检查一下。
    • @AmolBLande 你能更新一下你在这个问题上的状态吗?
    • @AmolBLande 欢迎。很高兴为您提供帮助。
    • 这里没有输入?现在从一个类型化的对象到一个松散的无名的参数定义类型。 Angular 的表现并不出色。
    猜你喜欢
    • 1970-01-01
    • 2019-05-27
    • 2016-06-24
    • 1970-01-01
    • 2022-11-10
    • 2018-09-22
    • 2018-09-01
    • 2017-03-31
    • 2018-11-11
    相关资源
    最近更新 更多