Error while importing RxJS operators in Angular

Viewed 155

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?

1 Answers

The import statements depend on the RxJS version.

RxJS 5+

import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/toPromise';

RxJS 6+

import { catchError, tap } from 'rxjs/operator';

The catch and do operators were replaced with catchError and tap respectively. Nothing has to be imported for toPromise since it isn't pipeable and invoked directly on an observable.

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.

Related