0

私はこれであなたの助けが必要:二ヶ月前、私のイオン2のアプリは、このコードで、ScreenOrientationのコルドバのプラグインを使用して、右に働いていた:新しいノートパソコンでイオン2 ScreenOrientationプラグインの変更

window.addEventListener('orientationchange',()=>{ 
    console.info('DEVICE ORIENTATION CHANGED!'); 
    console.debug(ScreenOrientation.orientation); 
    if(ScreenOrientation.orientation.type.indexOf('landscape') !== -1){ 
    this.screenOrientationIsPortrait = false; 
    } else if(ScreenOrientation.orientation.type.indexOf('portrait') !== -1){ 
    this.screenOrientationIsPortrait = true; 
    } 
}); 

、私が最も最近のイオン2バージョンをインストールし、そしてコルドバScreenOrientationプラグインの最新バージョン、および同じアプリのコードと、そして - 私は、コンパイル時にこのエラーを取得:

プロパティ「型」んタイプ 'string'には存在しません。

私はScreenOrientationプラグインのgithubのリポジトリ内の例を使用してみました:

window.addEventListener('orientationchange',()=>{ 
    console.info('DEVICE ORIENTATION CHANGED!'); 
    console.debug(ScreenOrientation.orientation); 
    if(screen.orientation.type.indexOf('landscape') !== -1){ 
    this.screenOrientationIsPortrait = false; 
    } else if(screen.orientation.type.indexOf('portrait') !== -1){ 
    this.screenOrientationIsPortrait = true; 
    } 
}); 

が、そのコードで、 - 私は、コンパイル時にも、このエラーを取得:

プロパティ'方向'はタイプ 'スクリーン'にはありません

両方とも、Ionic 2とScreenOrientaプラグインが最近更新されました。私の研究に基づいて、TypeScriptのエラーが表示されます。バージョンの競合は更新されません。

どうしたら間違っているのか分かりますか?この新しいエラーの原因を見つけるためにデバッグするにはどうすればよいですか?何か案は?事前にありがとう、私はあなたの助けに感謝します。

のGithubレポ例:https://github.com/apache/cordova-plugin-screen-orientation

イオン2例:https://ionicframework.com/docs/v2/native/screen-orientation/

答えて

0

あなたが実際にあまりにもプラグインを追加することなく、画面の向きの変化を検出することができます。タイプウィンドウのプロパティの向きを使用します。

window.addEventListener('orientationchange',() => { 
     console.info('DEVICE ORIENTATION CHANGED!'); 
     console.debug(ScreenOrientation.orientation); 
     switch (window.orientation) { 
     case -90: 
     case 90: 
       console.log("Landscape orientation"); 
       this.screenOrientationIsPortrait = true; 
       break; 
     case 0: 
      console.log("Landscape orientation"); 
       this.screenOrientationIsPortrait = false; 
      break; 
     }  
    }); 
+0

あなたの助けを借りて、私はあなたの解決策を使用しており、それはうまく動作します。しかし、私はプラグインとtypeScriptエラーの理由を見つけませんでした。よろしく。 – maguilleng

関連する問題