Detect screen orientation change

Is there a way to detect screen orientation change?

I need this to trigger a function which updates the variable used in split-pane when attribute. In my app user can customize the split pane appearance and this is the only way I can make it work properly.

This code works when running in browser but not in android device.
window.addEventListener(“orientationchange”, function() {
alert(window.orientation);
}, false);

Hey man, have you found any solution to this?

There was no need to detect screen orientation at all. If you give to the when attribute a string value it handles all by itself. So instead of giving a boolean value I set split pane when attribute like this:

<ion-split-pane [when]="myVariable">

And you can define myVariable like this:

let myWidth = '500px'
this.myVariable = '(min-width: ' + myWidth + ')';

If your question was only relating to screen orientation change, that code in starting post should actually work!

Thanks for sharing, man.

However in my case, I had a different problem.

Currently ion-slides has a bug when orientation changes.

In the meantime, I found this though.

A native plugin that can lock the screen orientation and also notify you when it has changed.