[英]Error while importing RxJS operators in Angular
I am getting this error.我收到此错误。 I'm trying to use我正在尝试使用
import { catchError } from 'rxjs/operators'
instead of代替
import 'rxjs/add/operator/catch'
But what to use instaed of rxjs/add/operator/do
and rxjs/add/operator/toPromise
?但是如何使用 rxjs rxjs/add/operator/do
和rxjs/add/operator/toPromise
呢?
The import statements depend on the RxJS version.导入语句取决于 RxJS 版本。
RxJS 5+ RxJS 5+
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/toPromise';
RxJS 6+ RxJS 6+
import { catchError, tap } from 'rxjs/operator';
The catch
and do
operators were replaced with catchError
and tap
respectively. catch
和do
运算符分别替换为catchError
和tap
。 Nothing has to be imported for toPromise
since it isn't pipeable and invoked directly on an observable.无需为toPromise
导入任何内容,因为它不可通过管道传输并直接在可观察对象上调用。
Also, if you're using toPromise
you need to know that it is being deprecated in RxJS 7 and will be gone in RxJS 8.此外,如果您正在使用toPromise
,您需要知道它在 RxJS 7 中已被弃用,并将在 RxJS 8 中消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.