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

Answer by Chris Stanley for Angular window resize event

$
0
0

I know this was asked a long time ago, but there is a better way to do this now! I'm not sure if anyone will see this answer though. Obviously your imports:

import { fromEvent, Observable, Subscription } from "rxjs";

Then in your component:

resizeObservable$: Observable<Event>resizeSubscription$: SubscriptionngOnInit() {    this.resizeObservable$ = fromEvent(window, 'resize')    this.resizeSubscription$ = this.resizeObservable$.subscribe( evt => {      console.log('event: ', evt)    })}

Then be sure to unsubscribe on destroy!

ngOnDestroy() {    this.resizeSubscription$.unsubscribe()}

Viewing all articles
Browse latest Browse all 20

Trending Articles



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