I am upgrading my app to Angular 6. I am upgrading from Angular 4, but the code below is causing errors in Angular 6, where it worked fine in Angular 4.
The errors I am getting:
Property 'of' does not exist on type 'typeof Observable'
Error: Property 'catch' does not exist on type 'Observable'
How should I resolve these errors?
private authInterceptor(observable: Observable<Response>): Observable<Response> {
return observable.catch((error, source) => {
if (error.status == 401) {
this.router.navigateByUrl('/login');
return Observable.of();
} else {
return Observable.throw(error);
}
});
}
Need to import the catch operator
you will need to import all operators you are using.
I am assuming you have migrated to RXJS6 since you have also migrated to angular6.
In RXJS6 use catch Error instead of catch as seen here
This worked for me, I'am using Angular 6.1.0.
Import the Library with following method and rearrange the code
This worked for me.
Or import Observable this way: