【问题标题】:'Headers' has no properties in common with type 'RequestOptionsArgs''Headers' 与类型 'RequestOptionsArgs' 没有共同的属性
【发布时间】:2017-09-12 23:06:02
【问题描述】:

我将 Angular 库升级到 4.3.6,将 tslint 升级到 5.7.0,在构建 Angular 应用程序时出现以下错误。

我没有在下面的代码中使用 RequestOptionsArgs,但出现以下错误

错误

Type 'Headers' has no properties in common with type 'RequestOptionsArgs'.

我的角度服务代码如下

import { Injectable } from '@angular/core';
import {Summary} from './summary';
import {Http, Headers, Response} from '@angular/http';
import { Observable } from 'rxjs/Observable';
import {SelectItem} from "primeng/primeng";
import {ExceptionHandle} from "../util/exceptionhandle";
import {MYCONST} from "../util/constants";

@Injectable()
export class MyService {

  private myUrl= MYCONST.reconURL.url;
  private headers: Headers = new Headers({"Content-Type'" : 'application/json',
                            'Accept': 'application/json',
                            'Access-Control-Allow-Origin':'*',
                            'Access-Control-Allow-Credentials':'true'
  });

  getSummaries(): Observable<Summary[]> {
    return this.http.get(this.reconUrl + '/summaries', this.headers)
      .map((response: Response) => <Summary[]> response.json())
      .catch(this.handleError);
  }

  private handleError(error: any): Promise<any> {
    return ExceptionHandle.handleError(error);
  }

}

【问题讨论】:

    标签: angular tslint


    【解决方案1】:

    你在错误的地方传递了headers 参数。您应该在http.get 方法中将headers 作为RequestOptionsArgs 对象的属性传递

    return this.http.get(this.reconUrl + '/summaries', { headers: this.headers }) 
    

    【讨论】:

      猜你喜欢
      • 2017-11-27
      • 1970-01-01
      • 2019-05-21
      • 2023-01-05
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 2022-08-10
      相关资源
      最近更新 更多