我用的是Ionic 3。我用了
ionic cordova plugin add cordova-plugin-screen-orientation
npm install @ionic-native/screen-orientation
app.module.ts
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
@NgModule({
providers: [
ScreenOrientation,
...
在我的page.ts
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
ionViewDidLoad() {
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);
Vs代码没有显示任何错误,但我在运行时收到以下错误:
TypeError: Object(...) is not a function
at ScreenOrientation.lock(http://10.18.2.70:8100/build/vendor.js:...)
发布于 2019-05-03 11:46:46
试试这个:
declare var window;
ionViewDidLoad() {
window.screen.orientation.lock('landscape');
}
https://stackoverflow.com/questions/55968458
复制