RxJS Operators You Will Use Every Day

Angular 17 min min read Updated: Nov 16, 2026 Intermediate
RxJS Operators You Will Use Every Day
Intermediate Topic 3 of 5

pipe and Operators

Operators are small functions that change a stream. You chain them inside pipe().

typescript import { of } from 'rxjs'; import { map, filter, tap } from 'rxjs/operators'; // or: import { map } from 'rxjs' of(1, 2, 3, 4, 5, 6).pipe( filter(n => n % 2 === 0), // 2, 4, 6 map(n => n * 10), // 20, 40, 60 tap(n => console.log('step', n)) // side effect, does not change values ).subscribe(console.log);

Most Useful Operators

OperatorWhat it does
mapTransform each value
filterKeep values that pass a test
tapDo something without changing the value (logging)
take(n) / takeUntilStop after n values or when another stream emits
debounceTime(ms)Wait until the user stops typing
distinctUntilChangedIgnore repeated identical values
switchMapSwitch to a new inner observable and cancel the previous one
catchErrorHandle errors and continue with a fallback
retry(n)Try again on error
startWithEmit a value first
combineLatestCombine the latest values of several streams
forkJoinWait for several observables to finish, then emit all results
finalizeRun code on complete or error (hide a spinner)

Live Search: the Classic Example

typescript import { FormControl, ReactiveFormsModule } from '@angular/forms'; import { debounceTime, distinctUntilChanged, switchMap, catchError, of } from 'rxjs'; @Component({ selector: 'app-search', imports: [ReactiveFormsModule], template: ` <input [formControl]="query" placeholder="Search products"> @for (p of results(); track p.id) { <p>{{ p.name }}</p> } `, }) export class Search { private http = inject(HttpClient); query = new FormControl('', { nonNullable: true }); results = toSignal( this.query.valueChanges.pipe( debounceTime(300), // wait for a pause in typing distinctUntilChanged(), // ignore same text switchMap(text => text.length < 2 ? of([]) : this.http.get<Product[]>('/api/products', { params: { q: text } }).pipe( catchError(() => of([])))), // an error must not kill the stream ), { initialValue: [] as Product[] }); }
Why switchMap? If the user types again before the old request finishes, switchMap cancels the old request. You never show old results over new ones.

Flattening Operators Compared

OperatorBehaviorUse for
switchMapCancel previous, use the newestSearch, route params, autocomplete
mergeMapRun all in parallelIndependent actions, order not important
concatMapOne after another, in orderSaves that must keep order
exhaustMapIgnore new while one is runningLogin button, prevent double submit

Combine Streams

typescript // latest page + latest filter -> reload const vm$ = combineLatest([page$, filter$]).pipe( switchMap(([page, filter]) => this.api.load(page, filter))); // several requests at once forkJoin({ user: this.http.get<User>('/api/me'), orders: this.http.get<Order[]>('/api/orders'), }).subscribe(({ user, orders }) => { /* both ready */ });

Errors and Retry

typescript this.http.get<Data>(url).pipe( retry({ count: 2, delay: 1000 }), catchError(err => { console.error(err); return of(null); // fallback value }), finalize(() => this.loading.set(false)), ).subscribe(d => this.data.set(d));
Nested subscribe: Do not subscribe inside subscribe. Use switchMap or another flattening operator.

Conclusion

pipe chains operators. Learn map, filter, debounceTime, switchMap, catchError and combineLatest and you can solve most real tasks such as search boxes and dependent requests.

Quick Summary: switchMap for latest, debounceTime for typing, catchError inside the inner stream.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators