I need to detect the change between the orientation of a device at runtime:
trying to use the Screen Api (https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation) on an Angular project I am receiving an error: Property 'orientation' does not exist on type 'Screen'
.
Orientation is not present in the Screen interface!
That some solutions that I was trying to replicate, without having success:
- How do I correctly detect orientation change using javascript and Phonegap in IOS?
How could I achieve it in a cross-browser friendly way?
Scenario:
count = 0;
countState() {
(window.screen.orientation.type === 'landscape-primary' || window.screen.orientation.type === 'landscape-secondary') ? count++ : count--;
}
<button (click)="countState()">Count</button>