Screen orientation lock is not working in ionic

Viewed 1890

I'm building an app using ionic@2.2.1, and I'm trying to control my screen orientation for each screen. I'm using the plugin cordova-plugin-screen-orientation@2.0.2.

and I use the following code to change the orientation

  screen.orientation.unlock();
  screen.orientation.lock('portrait');

However my screen orientation doesn't change. I'm getting this error when inspecting the code.

Uncaught (in promise) DOMException: screen.orientation.lock() is not available on this device.

Please help.

1 Answers

The problem is not with any plugin. The reason for this not working is that Cordova doesn't run with the command ionic serve. So it'll not work in the inspect tab. Use an emulator instead, it'll work just fine.

Related