【问题标题】:Type 'ResponseContentType.ArrayBuffer' is not assignable to type '"json类型 'ResponseContentType.ArrayBuffer' 不可分配给类型 '"json
【发布时间】:2019-02-11 23:34:19
【问题描述】:

我目前正在将我的 Angular 应用程序升级到 Angular 7。出现以下错误。只是为了让你知道我正在使用 httpclient。不确定是什么问题。

类型 'ResponseContentType.ArrayBuffer' 不可分配给类型 '"json。错误位于 responseType: ResponseContentType.ArrayBuffer 行

previewDocument(id: number) {
        //var pars = new URLSearchParams();
        let pars = new HttpParams();
        pars.set('id', id.toString());
        return this.http.get(this.config.api.previewDocument, { search: pars, withCredentials: true,  responseType: ResponseContentType.ArrayBuffer });
    }

【问题讨论】:

    标签: angular


    【解决方案1】:

    ResponseContentType 已弃用。如果您请求非 JSON 数据,请查看文档以获取示例 here

    以下类型可用:'arraybuffer' | '斑点' | 'json' | '文本'

    我假设你会使用responseType: 'arraybuffer'

    【讨论】:

    • 我看过这个例子所以你的意思是它会像这样 return this.http.get(this.config.api.previewDocument, { params: pars, withCredentials: true, responseType: 'arraybuffer ' });
    • 我假设没有枚举
    • 是的,正如您在评论中所写的那样。它对你有用吗?
    • 能否请您建议,我需要从哪里导入 responseType?
    猜你喜欢
    • 2020-04-02
    • 2019-06-02
    • 2018-01-04
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-26
    相关资源
    最近更新 更多