Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any window event for orientation change using @HostListener like we have @HostListener("window:scroll", ['$event']) for scrolling? [duplicate]

I want to detect orientation change, to detect I am viewing my application in portrait mode or in landscape mode.So is there any event like orientation change which I can pass inside hostlistener in my component to detect orientation change?

P.S - Some guys are saying it duplicate question.I don't want plain java script way, I wanted the angular way to detect orientation change.

like image 803
gaurav gupta Avatar asked Dec 14 '22 11:12

gaurav gupta


1 Answers

From MDN; you can use window:orientationchange to detect when the orientation of the device has changed.

@HostListener('window:orientationchange', ['$event'])
onOrientationChange(event) {
  console.log('orientationChanged');
}

Here is a short clip to see this in action in Chrome Dev Tools: https://streamable.com/o2ilm

like image 81
Andrew Hill Avatar answered May 22 '23 00:05

Andrew Hill