Как реализовать новейшую ориентацию экрана в ionic 3, поскольку он не обнаруживает встроенную функцию замены? - PullRequest
1 голос
/ 10 мая 2019

Я также искал похожие проблемы, но ни одна из них не работала в моем случае.

Я установил плагин для ориентации экрана во вновь созданном приложении и запустил его с функциями по умолчанию.
но это всегда показывает ошибку,

Ионная информация:

Ionic:

   ionic (Ionic CLI)  : 4.0.2 (C:\Users\Anurag\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.5
   @ionic/app-scripts : 3.2.2

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : not available

System:

   Android SDK Tools : 26.1.1
   NodeJS            : v8.10.0 (C:\Program Files\nodejs\node.exe)
   npm               : 5.6.0
   OS                : Windows 10

нижеуказанная ошибка отображается при получении текущего типа ориентации экрана:

ERROR TypeError: Object(...) is not a function  
    at ScreenOrientation.get [as type] (vendor.js:81072)  
    at HomePage.webpackJsonp.248.HomePage.getCurrentScreenOrientation (main.js:64)  
    at Object.eval [as handleEvent] (HomePage.html:11)  
    at handleEvent (vendor.js:14225)  
    at callWithDebugContext (vendor.js:15734)  
    at Object.debugHandleEvent [as handleEvent] (vendor.js:15321)  
    at dispatchEvent (vendor.js:10640)  
    at vendor.js:11265  
    at HTMLButtonElement.<anonymous> (vendor.js:40134)  
    at t.invokeTask (polyfills.js:3)  

нижеуказанная ошибка отображается при изменении состояния ориентации экрана:

ERROR TypeError: Object(...) is not a function  
    at ScreenOrientation.onChange (vendor.js:81068)  
    at HomePage.webpackJsonp.248.HomePage.observeScreenOrientation (main.js:84)  
    at Object.eval [as handleEvent] (HomePage.html:14)  
    at handleEvent (vendor.js:14225)  
    at callWithDebugContext (vendor.js:15734)  
    at Object.debugHandleEvent [as handleEvent] (vendor.js:15321)  
    at dispatchEvent (vendor.js:10640)  
    at vendor.js:11265  
    at HTMLButtonElement.<anonymous> (vendor.js:40134)  
    at t.invokeTask (polyfills.js:3)  

home.html:

<ion-header>  
    <ion-navbar>  
        <button ion-button menuToggle>  
            <ion-icon name="menu"></ion-icon>  
        </button>  
        <ion-title>Screen Orientation</ion-title>  
    </ion-navbar>  
</ion-header>  

<ion-content padding>  
    <button ion-button clear block secondary (click)="getCurrentScreenOrientation()"> Get Orientation </button>  

    <button ion-button clear block secondary (click)="observeScreenOrientation()"> Observe Orientation </button>  
</ion-content>  

home.ts:

import { Component } from '@angular/core';  
import { NavController } from 'ionic-angular';  
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';  

@Component({  
    selector: 'page-home',  
    templateUrl: 'home.html'  
})  
export class HomePage {  

    constructor(public navCtrl: NavController, private screenOrientation: ScreenOrientation) {
    }


    getCurrentScreenOrientation() {  
        console.log('getCurrentScreenOrientation: ', this.screenOrientation.type);  
    }  


    observeScreenOrientation() {  
        this.screenOrientation.onChange()
    .subscribe(() => console.log('Orientation Changed'));
    }  

}

1 Ответ

2 голосов
/ 10 мая 2019

/ngx расширение для ионного 4 и далее, оно не будет работать для ионного 3 и выбросит это

TypeError: Object(...) is not a function 

, поэтому я предлагаю вам использовать документацию V3 и реализовать ее для проекта ionic 3 https://ionicframework.com/docs/v3/native/screen-orientation /

...