Reputation: 4878
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?
Upvotes: 6
Views: 4472
Reputation: 329
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}
]
Upvotes: 10
Reputation: 1401
Delete the parameter “public orientation:ScreenOrientation” from the constructor function.
Upvotes: 0