Angular और TypeScript में http.get(...).map is not a function त्रुटि
सभी को नमस्ते! मैं Angular और TypeScript सीखना शुरू कर रहा हूँ, API के लिए एक सरल HTTP GET अनुरोध करने का प्रयास कर रहा हूँ। CLI के माध्यम से Angular इंस्टॉल किया, एक service बनाया और डेटा प्राप्त करने का प्रयास कर रहा हूँ। HttpClient का उपयोग कर रहा हूँ, लेकिन get method को कॉल करने और RxJS से map operator को लागू करने का प्रयास करने पर यह त्रुटि मिलती है: "http.get(...).map is not a function in [null]"। यहाँ मेरा कोड है:
```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()
);
}
}
```
और component में:
```typescript
i