卡在离子屏幕方向上

时间:2019-05-03 11:00:08

标签: ionic3 screen-orientation

我正在使用Ionic3。我做了

ionic cordova plugin add cordova-plugin-screen-orientation
npm install @ionic-native/screen-orientation

app.module.ts

import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';

@NgModule({

   providers: [
     ScreenOrientation,
     ...

在我的page.ts上:

import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';

ionViewDidLoad() {
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);

VS代码未显示任何错误,但在运行时出现以下错误:

TypeError: Object(...) is not a function
    at ScreenOrientation.lock(http://10.18.2.70:8100/build/vendor.js:...)

1 个答案:

答案 0 :(得分:2)

尝试一下:

declare var window;

ionViewDidLoad() {
    window.screen.orientation.lock('landscape');
}