farahm
farahm

Reputation: 1326

Stuck with Ionic ScreenOrientation

I am using Ionic 3. I did

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,
     ...

On my page.ts:

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

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

Vs Code is not showing any error, but I get following error during runtime:

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

Upvotes: 0

Views: 1548

Answers (2)

Diego
Diego

Reputation: 719

For ionic3 use:

npm install @ionic-native/screen-orientation@4

Upvotes: 0

Dharti Gohil
Dharti Gohil

Reputation: 121

Try this:

declare var window;

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

Upvotes: 2

Related Questions