加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular2 – 属性’catch’在类型’Observable’上不存在

发布时间:2020-12-17 08:27:02 所属栏目:安全 来源:网络整理
导读:在使用Http服务的Angular 2文档页面上,有一个例子。 getHeroes (): ObservableStuff[] { return this.http.get(this.url) .map(this.extractData) .catch(this.handleError);} 我克隆了angular2-webpack-starter项目,自己添加了上面的代码。 我导入了Obser
在使用Http服务的Angular 2文档页面上,有一个例子。
getHeroes (): Observable<Stuff[]> {
  return this.http.get(this.url)
                  .map(this.extractData)
                  .catch(this.handleError);
}

我克隆了angular2-webpack-starter项目,自己添加了上面的代码。

我导入了Observable使用

从“rxjs / Observable”导入{Observable};

我假定属性Observable也被导入(.map)。看到rxjs.beta-6的changelog,没有提到catch。

是的,您需要导入运算符:
import 'rxjs/add/operator/catch';

或以这种方式导入Observable:

import {Observable} from 'rxjs/Rx';

但在这种情况下,您将导入所有运算符。

有关详细信息,请参阅此问题:

> Angular 2 HTTP GET with TypeScript error http.get(…).map is not a function in [null]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读