Angular 离子4-屏幕方向(纵向)不工作,NullInjectorError
我是爱奥尼亚4的新手,我正在尝试将屏幕方向设置为纵向,但我在爱奥尼亚4的屏幕方向插件上遇到了问题。 我已经尝试了一段时间其他的方法,但这些也不起作用。我不能让这个插件解决这个进口问题。我在构造函数问题中有太多的参数确认。 我在手机上安装了这个apk,但它不工作 以下是tabs.page.ts:Angular 离子4-屏幕方向(纵向)不工作,NullInjectorError,angular,ionic-framework,ionic4,screen-orientation,ionic-native,Angular,Ionic Framework,Ionic4,Screen Orientation,Ionic Native,我是爱奥尼亚4的新手,我正在尝试将屏幕方向设置为纵向,但我在爱奥尼亚4的屏幕方向插件上遇到了问题。 我已经尝试了一段时间其他的方法,但这些也不起作用。我不能让这个插件解决这个进口问题。我在构造函数问题中有太多的参数确认。 我在手机上安装了这个apk,但它不工作 以下是tabs.page.ts: import { Component } from '@angular/core'; import { MenuController, Platform } from '@ionic/angular';
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:
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 {}
下面是错误:
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)
如果我没记错的话,如果您使用的是Ionic Cordova,那么必须在文件
config.xml
中添加这些代码行
<preference name="Orientation" value="portrait" />
<preference name="Fullscreen" value="true" />
我认为这应该解决它
对于这个错误,您能告诉我您是在什么平台上编译的吗?您是在Cordova还是Capactor上?