Error http.get(...).map is not a function en Angular y TypeScript
¡Hola a todos! Empecé a estudiar Angular y TypeScript, estoy intentando hacer una simple solicitud HTTP GET a una API. Instalé Angular a través de CLI, creé un servicio y estoy intentando obtener datos. Estoy usando HttpClient, pero al llamar al método get e intentar aplicar el operador map de RxJS recibo el error: "http.get(...).map is not a function in [null]". Aquí está mi código:
```typescript
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class DataService {
private apiUrl = 'https://jsonplaceholder.typicode.com/posts';
constructor(private http: HttpClient) { }
getPosts() {
return this.http.get(this.apiUrl).map(
(response: Response) => response.json()
);
}
}
```
Y en el componente:
```typescript
i
No answers yet.
Inicia sesión para dejar una respuesta