【发布时间】:2018-04-16 10:55:32
【问题描述】:
我需要在运行时检测设备方向之间的变化:
尝试在 Angular 项目中使用 Screen Api (https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation) 我收到一个错误:Property 'orientation' does not exist on type 'Screen'。
屏幕界面中不存在方向!
我试图复制的一些解决方案没有成功:
- How do I correctly detect orientation change using javascript and Phonegap in IOS?
如何以跨浏览器友好的方式实现它?
场景:
count = 0;
countState() {
(window.screen.orientation.type === 'landscape-primary' || window.screen.orientation.type === 'landscape-secondary') ? count++ : count--;
}
<button (click)="countState()">Count</button>
【问题讨论】:
标签: javascript angular window orientation screen-orientation