Created
August 5, 2020 09:52
-
-
Save codeepic/50dc83a490cd9019fb8812caf5d61df5 to your computer and use it in GitHub Desktop.
How to subscribe to window resize event in Angular using RxJS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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