Quantcast
Channel: Angular window resize event - Stack Overflow
Viewing all articles
Browse latest Browse all 20

Answer by A. Morel for Angular window resize event

$
0
0

If you want just one event after the resize is finished, it's better to use RxJS with debounceTime :debounceTime: Discard emitted values that take less than the specified time between output.

He waits > 0.5s between 2 events emitted before running the code.In simpler terms, it waits for the resizing to be finished before executing the next code.

// RxJS v6+import { fromEvent } from 'rxjs';import { debounceTime, map } from 'rxjs/operators';...const resize$ = fromEvent(window, 'resize');    resize$      .pipe(        map((i: any) => i),        debounceTime(500) // He waits > 0.5s between 2 events emitted before running the next.      )      .subscribe((event) => {        console.log('resize is finished');      });

StackBlitz example

StackBlitz


Viewing all articles
Browse latest Browse all 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>