在“task.service.ts”文件中我有:
getBooks(): Observable<Book[]> {
return this.http.get('http://localhost:3000/books')
.map((res) => res.json());
}
我收到消息:“ map ”不存在。所以,我在顶部添加了: import 'rxjs' 现在我收到一条错误消息: "**
error TS 2339: Property
JSON
does not exist on type 'Object'
**。”
我做错了什么?我忘记了什么?
最佳答案
使用 HttpClient
,您不需要 map(res => res.json())
getBooks(): Observable<Book[]> {
return this.http.get<Book[]>('http://localhost:3000/books');
}
关于json - 错误 TS2339 : Property 'json' does not exist on type 'Object' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48650010/