I am trying to create new wrapper for restservice, i am trying to move angular 4 to 5 and upgrading the same service. i get error like below. If i change Observable<Response>
to Observable<HttpResponse>
also i get error:
Argument of type 'HttpHeaders' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
Property 'headers' is private in type 'HttpHeaders' but not in type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?:
below is code.
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { HttpClient, HttpRequest, HttpHeaders, HttpResponse } from '@angular/common/http';
@Injectable()
export class httpService {
private requestHeaders: HttpHeaders;
constructor(private _http: HttpClient) {
this.requestHeaders = new HttpHeaders();
this.requestHeaders.append('Content-Type', 'application/json');
this.requestHeaders.append('Accept', 'application/json');
}
post(url: string, requestData?: any): Observable<Response> {
return this._http.post(url, requestData, this.requestHeaders);
}
}
Above is fixed by using {headers: this.requestHeaders}
but while line return this._http.post(url, requestData, this.requestHeaders);
throws error like
Type 'Observable<ArrayBuffer>' is not assignable to type 'Observable<Response>'.
Type 'ArrayBuffer' is not assignable to type 'Response'.
Property 'body' is missing in type 'ArrayBuffer'.
Observable<Response>
as a return type ofhttpClient.get
. You can either useObservable<any>
orObservable<HttpResponse<any>>
. – Chau Tran