我试图从Angular调用一个API,但得到这个错误:

属性“map”在类型“Observable<Response>”上不存在

这个类似问题的答案并没有解决我的问题:Angular 2 beta版。17:属性“map”在类型“Observable<Response>”上不存在。

我使用的是Angular 2.0.0-beta.17。


当前回答

对于所有遇到此问题的Linux用户,检查rxjs-compat文件夹是否被锁定。我有这个完全相同的问题,我进入终端,使用sudo su给整个rxjs-compat文件夹的权限,它是固定的。假设你进口了

import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch'; 

在项目中。原始的.map错误发生在Ts文件中。

其他回答

只需运行NPM install—save rxjs-compat即可修复错误。

这里推荐

如果你使用这个旧的方法来获取路由参数

 this._route.params
        .map(params => params['id'])

为新的rxjs版本更新它

首先, 从RXJS操作符中导入映射。

import { map } from 'rxjs/operators';

第二个添加管道,

   this._route.params.pipe(
            map(params => params['id']))

再次讨论这个问题,因为我的解决方案没有列在这里。

我正在用rxjs 6.0运行Angular 6,遇到了这个错误。

下面是我解决问题的方法:

我改变了

map((response: any) => response.json())

简单地成为:

.pipe(map((response: any) => response.json()));

我在这里找到了解决方法:

https://github.com/angular/angular/issues/15548#issuecomment-387009186

angular的新版本不支持.map,你必须通过cmd安装 保存rxjs-compat 通过这个你可以享受老技术。 注意: 不要忘记导入这些行。

import { Observable, Subject } from 'rxjs';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';

感谢https://github.com/nagamallabhanu

https://github.com/webmaxru/pwa-workshop-angular/issues/2#issuecomment-395024755

封装

管(地图(…))

工作

import { map } from 'rxjs/operators';

courseRef: AngularFireList<any>;
courses$: Observable<any[]>;

this.courseRef = db.list('/tags');
  this.courses$ = this.courseRef.snapshotChanges()
  .pipe(map(changes => {
      return changes.map(c => ({ key: c.payload.key, ...c.payload.val() 
  }));
 }));
 this.courses$.subscribe(res=>{
   console.log(res)
 })