当我编写以下代码时,我正在使用angular6:
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
EditDetail(data) : Observable<Test[]> {
let url = "http://www.example.com/api/getdetails";
return this.httpClient.get(url).map((response: Response) => {
return <Test[]>response.json();
});我收到如下错误:
this.httpClient.get(...).map is not a function在浏览器控制台中。
我也尝试过
import { pipe } from 'rxjs';并使用
return this.httpClient.get(url).pipe(
map((response: Response) => <Test[]>response.json())
);但它显示的错误如下
this.httpClient.get(...).pipe is not a function发布于 2018-08-07 19:12:33
从RxJS 5.5开始,您需要pipe map函数。
return this.httpClient.get(url).pipe(
map((response: Response) => <Test[]>response.json())
);有关更多信息,请参阅。
发布于 2018-08-07 19:12:41
您可以尝试使用此解决方案。
this.httpClient.get(...).pipe(
map(data => res)
).subscribe((data):any=>{
console.log(data)
}) 发布于 2018-08-07 19:13:21
要使用map,请使用管道。您需要使用http客户端模块才能使用管道函数。将其导入并在构造函数中初始化
import {HttpClient} from '@angular/common/http';
this.httpClient.get(...).pipe(map(data => res))https://stackoverflow.com/questions/51725352
复制相似问题