Reputation: 79
I'm using cordova and I am trying to lock the screen orientation to landscape for Android. I'm using the plugin screen-orientation plugin: https://www.npmjs.com/package/cordova-plugin-screen-orientation
I'm using it in my javascript code as:
screen.lockOrientation("landscape");
But I get the error that screen.lockOrientation is not a function. I console.log(screen) and I see that the method does exist. I also added the plugin into my config.xml as the same question was asked here: How to configure plugin "cordova-plugin-screen-orientation" in config.xml
I'm still getting the error. Does anyone know how I can fix it?
Upvotes: 2
Views: 3442
Reputation: 93
As per the npm documentation, you can use
window.screen.orientation.lock('portrait');
Upvotes: 1
Reputation: 2209
This is for ionic 1.X.
man after a long struggle I found it out myself, never said in any documentation. First I used ionic native as said here (take the part for v1 - angular1) http://ionicframework.com/docs/v2/native/
then
Use injector '$cordovaScreenOrientation'. Will work only in device.
.controller('LoginCtrl', function($scope,$cordovaScreenOrientation) {
$cordovaScreenOrientation.lockOrientation('landscape')
....
Upvotes: 1