首页 文章

错误:类型'Observable'上不存在属性'map'

提问于
浏览
0

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

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

enter image description here

我尝试了所有可能的解决方案Property 'map' does not exist on type 'Observable<Response>'

但仍然存在错误 .

2 回答

  • 1

    当您提供代码而不是屏幕截图时,很容易发布答案 . Anyhow ,你必须 pipe 它:

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

    记得像这样导入 map

    import { map } from 'rxjs/operators';
    
  • 9

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

    import'rxjs / add / operator / map';

相关问题