timeoutWith 运算符 Angular 5 Httpcleint

timeoutWith operator Angular 5 Httpcleint

刚开始升级 angular 2.0.0 到 5.2.0。所以我正在使用 HttpClient 。 我想在 httpClient.get() 上使用 timeoutWith 运算符。我得到的只是 Property 'timeoutWith' does not exist on type 'Observable<Object>'.

someFunction(){
 let someUrl = '.../../' ;
return this._httpClient.get(url).timeoutWith(1000,this.throwTimeout()).catch(this.handleError);

}

我做错了什么?这与之前的 httpmodule

一起工作

谢谢

只需添加:

import 'rxjs/add/operator/timeoutWith';

现在 Observable 类型上的许多属性不再存在。

您需要从 rxjs 导入它。

import 'rxjs/add/operator/timeoutWith';

您可能应该导入其他属性,例如地图

import 'rxjs/add/operator/map'

这个 link 可以帮助您从 Angular 2 迁移到 Angular 5。

为了获得更好的性能,您应该单独导入可观察运算符。 它与 angular 及其 AOT 编译的指南一致。 拆分您的导入有助于编译器完成 tree shaking

因此,正如其他人已经写的那样,您需要添加 timeoutWith 运算符

import 'rxjs/add/operator/timeoutWith';

以及您需要使用的任何其他运算符。