Ionic 2 ScreenOrientation 插件更改
Ionic 2 ScreenOrientation Plugin Changes
我需要你的帮助:两个月前,我的 Ionic 2 应用程序运行正常,使用 ScreenOrientation cordova 插件,代码如下:
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;
}
});
在一台新笔记本电脑上,我安装了最新版本的 Ionic 2 和最新版本的 cordova ScreenOrientation 插件,并使用相同的应用程序代码,但我在编译时遇到了这个错误:
Property 'type' does not exist on type '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;
}
});
但是使用该代码,我在编译时也遇到了这个错误:
Property 'orientation' does not exist on type 'Screen'
最近更新了 Ionic 2 和 ScreenOrientation 插件。根据我的研究,它似乎是 TypeScript 错误,而不是更新版本冲突。
我怎么知道哪里出了问题?我如何调试才能找到这个新错误的原因?有任何想法吗?在此先感谢您的帮助。
Github 回购示例:https://github.com/apache/cordova-plugin-screen-orientation
离子 2 示例:https://ionicframework.com/docs/v2/native/screen-orientation/
您实际上可以在不添加插件的情况下检测屏幕方向变化。使用类型 window 的 属性 方向。
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;
}
});
我需要你的帮助:两个月前,我的 Ionic 2 应用程序运行正常,使用 ScreenOrientation cordova 插件,代码如下:
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;
}
});
在一台新笔记本电脑上,我安装了最新版本的 Ionic 2 和最新版本的 cordova ScreenOrientation 插件,并使用相同的应用程序代码,但我在编译时遇到了这个错误:
Property 'type' does not exist on type '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;
}
});
但是使用该代码,我在编译时也遇到了这个错误:
Property 'orientation' does not exist on type 'Screen'
最近更新了 Ionic 2 和 ScreenOrientation 插件。根据我的研究,它似乎是 TypeScript 错误,而不是更新版本冲突。
我怎么知道哪里出了问题?我如何调试才能找到这个新错误的原因?有任何想法吗?在此先感谢您的帮助。
Github 回购示例:https://github.com/apache/cordova-plugin-screen-orientation
离子 2 示例:https://ionicframework.com/docs/v2/native/screen-orientation/
您实际上可以在不添加插件的情况下检测屏幕方向变化。使用类型 window 的 属性 方向。
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;
}
});