1// <button (click)="clickEvent.next()">Click Me</button>
2
3class YourComponent implements OnInit {
4
5 clickEvent = new Subject();
6
7 ngOnInit() {
8 // throttleTime() executes the event immediately, and discards
9 // any new events until 300ms have passed.
10 this.clickEvent.pipe(throttleTime(300))
11 .subscribe(() => console.log('Clicked'));
12
13 // debounceTime() delays the event by 300ms, and the timer resets
14 // if another event occurs.
15 this.clickEvent.pipe(debounceTime(300))
16 .subscribe(() => console.log('Clicked');
17
18 // remember to unsubscribe() !!!
19 }
20}