i've been working in a project with Angular 11, where i'm using HttpClientModule and RxJS for cosume the SWAPI. I have this code and i for get the people, but i can't because when try to convert the data to JSON i get the message "property name does not exist on type promise"
My code of this service is:
import { Injectable } from '@angular/core';
import { People } from './people';
import { Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import 'rxjs/add/operator/catch'
import { HttpClient } from '@angular/common/http';
@Injectable()
export class PeopleService {
constructor(private http: HttpClient) { }
getPeople(): Observable<People[]> {
return this.http
.get<People[]>("https://swapi.co/api/people")
.pipe(
map(this.toJSON),
catchError(err => this.handleError)
)
}
private toJSON(res: Response) {
const json = res.json();
return json.results || json.data;
}
}