关于angular:错误:类型“ Observable”上不存在属性“ map”

Error: Property 'map' does not exist on type 'Observable'

更新angular / cli后,出现错误:

1
error TS2339: Property 'map' does not exist on type 'Observable<Response>'

enter image description here

我尝试了Observable 类型上属性映射中不存在的所有可能解决方案

但错误仍然存在。


当您提供代码而不是屏幕截图时,很容易发布答案。 无论如何,您必须pipe它:

1
2
3
4
5
getUsers() {
    return this._http.get(this.baseUrl+'/show-users', this.options)
                     .pipe(
                          map((response:Response)=>response.json())
                      );

记住要像这样导入map

1
import { map } from 'rxjs/operators';


对于最新版本的rxjs
我们需要从终端安装npm install rxjs-compat然后声明

导入'rxjs / add / operator / map';


您可以使用管道找到解决方案。 步骤如下...

首次导入地图

1
import {map} from 'rxjs/operators';

使用管道修改getuser()和其他所有功能

1
2
3
getUser(){
 this._http.get(this.baseUrl+'/show-users', this.options).pipe(map((response:Response)=>response.json()));                
}