Retorno angular de HttpClient esperando observável <HttpEvent <any> em vez de observável <any>
Estou recebendo um erro de compilação no tipo de retorno ao usar HttpClient. Na minha funçãoGetPortfolio
Estou esperando oGET
chamar para retornar o objeto json do tipoObservable<Portfolio>
mas está dando o erro:
TipoObservable<HttpEvent<Portfolio>>
não é atribuível ao tipoObservable<Portfolio>
. TipoHttpEvent<Portfolio>
não é atribuível ao tipoPortfolio
. TipoHttpProgressEvent
não é atribuível ao tipoPortfolio
. Propriedadename
está faltando no tipoHttpProgressEvent
.
Meu código:
import { Injectable } from '@angular/core';
import { environment } from './environments/environment';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
export interface Portfolio {
name: string;
id: string;
}
@Injectable()
export class PortfolioService {
private httpOptions;
apiUrl: string;
constructor(private http: HttpClient) {
this.apiUrl = environment.apiUrl + "/api/portfolios";
this.httpOptions = {
headers: new HttpHeaders(
{
'Content-Type': 'application/json',
})
};
}
GetPortfolio(portfolioId: string): Observable<Portfolio> {
return this.http.get<Portfolio>(this.apiUrl + '/${portfolioId}', this.httpOptions);
}
}
No tutorial do herói angular e nos documentos, as solicitações HttpClient devem esperarObservable<any>
: Doc HttpClient angular
Então, estou fazendo algo errado? Ou devo definir o valor de retorno comoObservable<HttpEvent<Portfolio>>
?