I am new on Ionic 4 and I am trying to set the screen orientation to landscape and referring to docs this is what I am doing:
...
import {ScreenOrientation} from '@ionic-native/screen-orientation';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private screenOrientation: ScreenOrientation,
) {
this.initializeApp();
}
initializeApp() {
this.screenOrientation.lock(ScreenOrientation.ORIENTATIONS.LANDSCAPE);
...
}
}
and during compilation, I get this error:
[ng] ERROR in src/app/app.component.ts(24,33): error TS2345: Argument of type 'string' is not assignable to parameter of type 'OrientationLockType'.
and on browser console:
Uncaught Error: Can't resolve all parameters for AppComponent: ([object Object], [object Object], [object Object], ?). at syntaxError (compiler.js:2426) [] ...
There is a problem in the injection for the fourth parameter, did you correctly install the screen orientation plugin?
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-screen-orientation/
If this doesn't work you should try this way ( withoud the import and injection )
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-screen-orientation/
Also, if you want to force landscape orientation for the whole application it is possibile to add a preference in config.xml
I've tested it and it works in android platform 7.1.4
Make sure to add
ScreenOrientation
to the providers array in the module using the plugin.For example in
app.module.ts
you use ionic V4, please see the doc, import correct things.
not