Angular : how to call finally() with RXJS 6 Angular : how to call finally() with RXJS 6 angular angular

Angular : how to call finally() with RXJS 6



Need to import finalize from rxjs/operators.

import { finalize } from 'rxjs/operators';

Then finalize is used inside the pipe(),

observable()    .pipe(          finalize(() => {              // Your code Here         })     )    .subscribe();


According to official document, You should change your code like this to avoid compile error: (You must throw exception in catchError method. finalize callback method has no argument.)

import { catchError, finalize } from 'rxjs/operators';return next.handle(clonedreq).pipe(  catchError(error => {    console.log('error occured:', error);    throw error;  }),  finalize(() => {    console.log('finalize')  }));

It is successfully compiled in Angular CLI: 7.1.4.