2017-11-03 10 views
0

ランタイム時のデバイスの向きの変化を検出する必要があります。 AngularプロジェクトでScreen Api(https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation)を使用しようとしました。エラーが表示されます:Property 'orientation' does not exist on type 'Screen'
画面インターフェイスに方向性がありません!JavaScriptで画面の向きを検出する

それ私が持っ成功せず、複製しようとしていたいくつかの解決策:
- 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> 

答えて

0

私は可能、簡単な解決策は、このようなものになるだろうとします

function getOrientation() { 
    if (window.outerWidth > window.outerHeight) { 
    return 'landscape'; 
    return 'portrait'; 
} 
+0

私はちょうどあなたが理解しやすくするために、質問**シナリオ**に追加何が必要なのでしょうか。 Pierreが返答しました(https://stackoverflow.com/a/4917796/6916104): '多くのデバイスでキーボードが表示されると、availableWidthは高さより大きくなり、誤って横向きになります。 ' このソリューションが私のニーズに合っているかどうかは分かりません。 – 39ro

関連する問題