
- RxJS Tutorial
- RxJS - Home
- RxJS - Overview
- RxJS - Environment Setup
- RxJS - Latest Updates
- RxJS - Observables
- RxJS - Operators
- RxJS - Working with Subscription
- RxJS - Working with Subjects
- RxJS - Working with Scheduler
- RxJS - Working with RxJS & Angular
- RxJS - Working with RxJS & ReactJS
- RxJS Useful Resources
- RxJS - Quick Guide
- RxJS - Useful Resources
- RxJS - Discussion
RxJS - Filtering Operator throttle
This operator will output as well as ignore values from the source observable for the time period determined by the input function taken as an argument and the same process will be repeated.
Syntax
throttle(durationSelector: Observable or Promise): Observable
Parameters
durationSelector − The argument durationSelector is an Observable or Promise that will ignore values from the values emitted from the source Observable.
Return value
It will return an observable that will throttle the values emitted from the source observable.
Example
import { fromEvent, interval } from 'rxjs'; import { throttle} from 'rxjs/operators'; let btn = document.getElementById("btnclick"); let btn_clicks = fromEvent(btn, 'click'); let case1 = btn_clicks.pipe(throttle(ev => interval(2000))); case1.subscribe(x => console.log(x));
When you click on the button the first click event will be emitted, the subsequent clicks will be delayed for the time given to throttle() operator.
Output

Advertisements