类型'Observable< any>'上不存在属性'catch' [英] Property 'catch' does not exist on type 'Observable<any>'

查看:637
本文介绍了类型'Observable< any>'上不存在属性'catch'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Http服务的Angular 2文档页面上,有一个例子。

On the Angular 2 documentation page for using the Http service, there is an example.

getHeroes (): Observable<Stuff[]> {
  return this.http.get(this.url)
                  .map(this.extractData)
                  .catch(this.handleError);
}

我克隆了 angular2-webpack-starter 项目并自行添加上述代码。

I cloned the angular2-webpack-starter project and added the above code myself.

我使用

import {Observable} from 'rxjs/Observable';

我假设属性 Observable 是也导入( .map 有效)。查看rxjs.beta-6的更改日志,并且没有提及 catch

I'm assuming the properties Observable are imported as well (.map works). Looked at the changelog for rxjs.beta-6 and nothing is mentioned about catch.

推荐答案

是的,您需要导入运营商:

Yes, you need to import the operator:

import 'rxjs/add/operator/catch';

或以这种方式导入 Observable

import {Observable} from 'rxjs/Rx';

但在这种情况下,您导入所有运营商。

But in this case, you import all operators.

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

See this question for more details:

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

这篇关于类型'Observable&lt; any&gt;'上不存在属性'catch'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆