I have a service like this:
import { Injectable } from "@angular/core";
import { Http, Response, Headers, RequestOptions } from "@angular/http";
import "rxjs/add/operator/map";
import { Usuario } from "../_models/usuarios";
import { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs/Observable";
import { User } from "../_models/user.model";
private serviceUrl = "apiUrl";
headers = new Headers({
Authorization:
"Bearer " + JSON.parse(localStorage.getItem("currentUser")).token,
"Content-Type": "application/json"
});
options = new RequestOptions({ headers: this.headers });
constructor(private http: Http, private httpClient: HttpClient) {}
getUser(): Observable<User[]> {
return this.httpClient.get<User[]>(this.serviceUrl);
}
Problem is when I try to send options to get method like:
getUser(): Observable<User[]> {
return this.httpClient.get<User[]>(this.serviceUrl, this.options);
}
It returns:
message: 'Argument of type 'RequestOptions' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'. Types of property 'headers' are incompatible. Type 'Headers' is not assignable to type 'HttpHeaders | { [header: string]: string | string[]; }'. Type 'Headers' is not assignable to type '{ [header: string]: string | string[]; }'. Index signature is missing in type 'Headers'.'
I try to change it using http instead httpClient like:
return this.http.get<User[]>(this.serviceUrl, this.options);
But now I get
message: 'Expected 0 type arguments, but got 1.'
What am I doing wrong?