0

Desarrollo una app y quiero que en una página en particular (se llama juego la página) la rotación sea portrait, SIEMPRE. las otras páginas, libres de rotar.

Seguí la documentación de screen-orientation, pero obtengo solo un mensaje de error como este:

ERROR TypeError: Object(...) is not a function
at ScreenOrientation.get [as type] (index.js:45)
at JuegoPage.webpackJsonp.447.JuegoPage.ionViewDidLoad (juego.ts:14)
at ViewController._lifecycle (view-controller.js:486)
at ViewController._didLoad (view-controller.js:369)
at NavControllerBase._didLoad (nav-controller-base.js:768)
at t.invoke (polyfills.js:3)
at Object.onInvoke (core.js:4760)
at t.invoke (polyfills.js:3)
at r.run (polyfills.js:3)
at NgZone.run (core.js:4577)

En detalle lo que hice:

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

en app.module.ts hice:

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

y en providers dentro de app.module.ts......

ScreenOrientation 

luego en juego.ts (la pagina especifica) hice:

import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
...
constructor(private screenOrientation: ScreenOrientation, bla bla
...
ionViewDidLoad() {
    console.log(this.screenOrientation.type);
  }

Mas detalles

global packages:
cordova (Cordova CLI) : 8.0.0

local packages:
@ionic/app-scripts : 3.2.0
Cordova Platforms : android 7.0.0
Ionic Framework : ionic-angular 3.9.2

System:
Android SDK Tools : 26.1.1
Node : v8.11.3
npm : 5.6.0
OS : Windows 8.1

1 respuesta 1

0

Prueba a añadir el siguiente código dentro de las llaves de tu constructor

    this.platform.ready().then(() => {
          this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
    });
2
  • Gracias David, continúa el error ERROR Error: Uncaught (in promise): TypeError: Object(...) is not a function TypeError: Object(...) is not a function at ScreenOrientation.lock (index.js:42)
    – Guille
    el 1 may. 2019 a las 13:34
  • Resuelto, era un problema en la instalación del plugin, he seguido la documentación, pero desde ionicframework.com/docs/v3/native/screen-orientation Muchas gracias
    – Guille
    el 4 may. 2019 a las 9:52

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.