I want to lock my screen orientation to landscape at particular page in my ionic2
app. So I import the plugin from ionic site and Cordova
screen orientation plugin too:
import { ScreenOrientation } from 'ionic-native';
Then I tried call it in my constructor
:
constructor(public navCtrl: NavController,
public orientation:ScreenOrientation
) {
ScreenOrientation.lockOrientation('Landscape');
}
But I got this error:
EXCEPTION: Error in ./Test class Test_Host - inline template:0:0 caused by: No provider for ScreenOrientation!
What seems to be the issue here?
The error is stating there is no provider available for the ScreenOrientation "service". In order to use these providers they must first be declared in app.module.ts.
To add ScreenOrientation to your list of providers in app.module.ts:
First add the import:import { ScreenOrientation } from '@ionic-native/screen-orientation';
Then add ScreenOrientation to your list of providers in @NgModule:providers: [
StatusBar,
SplashScreen,
ScreenOrientation,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With