Angular Docs: Rx Library | Operators
import { of } from 'rxjs';
import { filter, map } from 'rxjs/operators';
const squareOdd = of(1, 2, 3, 4, 5)
.pipe(
filter(n => n % 2 !== 0),
map(n => n * n)
);
// Subscribe to get values
squareOdd.subscribe(x => console.log(x));
RxJS provides many operators, but only a handful are used frequently. For a list of operators and usage samples, visit the RxJS API Documentation.
Note that, for Angular applications, we prefer combining operators with pipes, rather than chaining. Chaining is used in many RxJS examples.
AREA | OPERATORS |
---|---|
Creation | from , fromEvent , of |
Combination | combineLatest , concat , merge , startWith , withLatestFrom , zip |
Filtering | debounceTime , distinctUntilChanged , filter , take , takeUntil |
Transformation | bufferTime , concatMap , map , mergeMap , scan , switchMap |
Utility | tap |
Multicasting | share |