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

3.8k Views Asked by At

I upgraded my angular libraries to 4.3.6 and tslint to 5.7.0 and I get the below error while building my angular app .

I am not using RequestOptionsArgs in my code below but I get the below error

Error

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

My angular service code is as below

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

}
1

There are 1 best solutions below

0
On BEST ANSWER

You passed headers parameter in wrong place. You should pass headers as an property of RequestOptionsArgs object in http.get method

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