【问题标题】:Error: property map doesn't exist on type 'Observable<Response>'错误:“Observable<Response>”类型上不存在属性映射
【发布时间】:2018-11-26 13:46:40
【问题描述】:
import { Injectable } from '@angular/core';
import { Http, Response, Headers } from '@angular/http';
import 'rxjs/add/operator/map';

这部分不起作用。你能帮我解决这个问题吗?

【问题讨论】:

标签: node.js angular rxjs


【解决方案1】:

您正在使用 已弃用HttpModule,您应该改用 HttpClientModule
关于错误

“可观察”类型上不存在属性映射

RxJS v5.5.2+ 已移至 Pipeable 运算符,以改进树抖动并更轻松地创建自定义运算符。 现在需要使用pipe 方法组合operators
Refer This
新建导入

import { map} from 'rxjs/operators';

示例

myObservable
  .pipe(map(data => data * 2),)
  .subscribe(...);

修改后的代码

    getShoppingItems() { return this.http.get('localhost:3000/api/items')
    .pipe(map(res => res.json())); } }

【讨论】:

  • 非常感谢!你帮了我很多。上帝保佑你:)
  • 很高兴我能帮助 Mate,你能把它作为正确答案吗:)
猜你喜欢
  • 2016-10-31
  • 2016-09-09
  • 1970-01-01
  • 2020-12-18
  • 2018-03-18
  • 2016-12-01
  • 2018-11-30
  • 2018-02-01
相关资源
最近更新 更多