Skip to content

Instantly share code, notes, and snippets.

@codeepic
Created August 5, 2020 09:52
Show Gist options
  • Save codeepic/50dc83a490cd9019fb8812caf5d61df5 to your computer and use it in GitHub Desktop.
Save codeepic/50dc83a490cd9019fb8812caf5d61df5 to your computer and use it in GitHub Desktop.
How to subscribe to window resize event in Angular using RxJS.
subscribeToWindowResize(): void {
// maybe this could be run outside Angular
// https://blog.bitsrc.io/the-principles-for-writing-awesome-angular-components-10e45f9ae77e
fromEvent(window, 'resize')
.pipe(
debounceTime(1000),
tap(() => this.redrawChart()),
takeUntil(this.cmpDestroyed$)
)
.subscribe();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment