Dominika Es
Dominika Es

Reputation: 39

error TS2339: Property 'json' does not exist on type 'Object'

in the file 'task.service.ts' I have:

getBooks(): Observable<Book[]> {
    return this.http.get('http://localhost:3000/books')
        .map((res) => res.json());
}

and I get the message: "map"does not exist. So, I added at the top: import 'rxjs' and now I have an error message: "**

error TS 2339: Property JSON does not exist on type 'Object'

**."

What am I doing wrong? What I forgot about?

Upvotes: 2

Views: 7300

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222582

With HttpClient, you don't need map(res => res.json())

 getBooks(): Observable<Book[]> {
    return this.http.get<Book[]>('http://localhost:3000/books');
  }   

Upvotes: 6

Related Questions