[SOLVED] Error: Screen Orientation plugin use

Good day people!

I’m having an issue with this plugin.
I installed it with cordova plugin add cordova-plugin-screen-orientation (my cordova is in v6.3.1).

Then I added screen.lockOrientation('landscape') into my view’s controller, but the console returned me the next status:

TypeError: screen.lockOrientation is not a function

Any ideas of why this could be happening ?

Thanks in advance!

Do you want to fix the orientation ?
If so, you just have to add <preference name="orientation" value="lanscape" /> in config.xml`.

Thanks mvrc, but I’m trying to lock orientation depending on current view and the changes in config.xml changes the orientation in all the application.

I fixed it !
I needed to encapsulate the function like this

document.addEventListener("deviceready", onDeviceReady, false);
	function onDeviceReady(){
	screen.lockOrientation('landscape'); // or 'portrait'
};

I dunno why I have to do this or why it is not in the documentation, but I think it could help somebody else.