Reputation: 39
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
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