首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >离子四屏方向(纵向)不起作用,NullInjectorError

离子四屏方向(纵向)不起作用,NullInjectorError
EN

Stack Overflow用户
提问于 2020-04-02 04:39:20
回答 1查看 998关注 0票数 1

我是ION4的新手,我正在尝试将屏幕方向设置为纵向,但我在IONIC4的ScreenOrientation插件上遇到了问题。我已经尝试了一段时间,但这些方法也不起作用。我不能让这个插件在这个导入问题上起作用。我在构造函数中有太多的参数确认问题。我在手机上安装了这个apk,但它不能工作。

下面是tabs.page.ts:

代码语言:javascript
运行
复制
import { Component } from '@angular/core';
import { MenuController, Platform } from '@ionic/angular';
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';

@Component({
  selector: 'app-tabs',
  templateUrl: './tabs.page.html',
  styleUrls: ['./tabs.page.scss'],
})
export class TabsPage {

  constructor( private platform: Platform,
               private screenOrientation: ScreenOrientation ) {
    this.platform.ready().then(() => {
    this.screenOrientation.unlock();
    this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);
    });

   }

}

下面是app.module.ts:

代码语言:javascript
运行
复制
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { AlphabeticalOriginOrderPipe } from './pipes/alphabetical-origin-order.pipe';
import { NumericalCostOrderPipe } from './pipes/numerical-cost-order.pipe';
import { DateHourOrderPipe } from './pipes/date-hour-order.pipe';
import { ImageModalPageModule } from './image-modal/image-modal.module';
import { MenuComponent } from './components/menu/menu.component';
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';

@NgModule({
  declarations: [AppComponent, AlphabeticalOriginOrderPipe, NumericalCostOrderPipe, DateHourOrderPipe, MenuComponent],
  entryComponents: [],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, ImageModalPageModule],
  providers: [
    StatusBar,
    ScreenOrientation,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

下面是错误:

代码语言:javascript
运行
复制
ERROR Error: Uncaught (in promise): NotSupportedError: screen.orientation.lock() is not available on this device.
    at resolvePromise (zone-evergreen.js:797)
    at zone-evergreen.js:707
    at ZoneDelegate.invoke (zone-evergreen.js:359)
    at Object.onInvoke (core.js:39699)
    at ZoneDelegate.invoke (zone-evergreen.js:358)
    at Zone.run (zone-evergreen.js:124)
    at zone-evergreen.js:855
    at ZoneDelegate.invokeTask (zone-evergreen.js:391)
    at Object.onInvokeTask (core.js:39680)
    at ZoneDelegate.invokeTask (zone-evergreen.js:390)
EN

回答 1

Stack Overflow用户

发布于 2020-04-02 09:13:04

如果我没记错,如果您使用的是Ionic Cordova,则必须将这些代码行添加到文件config.xml中。

代码语言:javascript
运行
复制
<preference name="Orientation" value="portrait" />
<preference name="Fullscreen" value="true" />

我想这应该能解决这个问题。

对于这个错误,你能告诉我你是在什么平台上编译的吗?

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60979898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档