Can someone assist me with this issue? A while back, my Ionic 2 app was functioning correctly using the ScreenOrientation Cordova plugin and the following code:
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;
}
});
Upon installing the latest versions of Ionic 2 and the cordova ScreenOrientation plugin on a new laptop and using the same code, I encountered a compile time error:
Property 'type' does not exist on type 'string'.
I attempted to use the examples from the ScreenOrientation plugin's GitHub repository:
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;
}
});
However, this code also resulted in a compile time error:
Property 'orientation' does not exist on type 'Screen'
It seems like a TypeScript error rather than a version conflict. How can I diagnose and resolve these errors? Any suggestions or guidance would be greatly appreciated. Thank you!
Github repo examples: https://github.com/apache/cordova-plugin-screen-orientation
Ionic 2 Examples: https://ionicframework.com/docs/v2/native/screen-orientation/