Prev Next

Web / RxJs Interview questions

What is "tap" operator in RxJS?

The "tap" operator is used to perform side-effects for notifications from the source observable. Used when you want to affect outside the state with a notification without altering the notification.

import { of } from 'rxjs';
import { tap } from 'rxjs/operators';
 
const source = of(1, 2, 3, 4, 5)
 
source.pipe(
 tap(n => {
   if (n > 3) {
     throw new TypeError(`Value ${n} is greater than 3`)
   }
 })
)
.subscribe(console.log);

More Related questions...

Show more question and Answers...


Comments & Discussions