我正在使用Ionic3。我做了
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:...)
答案 0 :(得分:2)
尝试一下:
declare var window;
ionViewDidLoad() {
window.screen.orientation.lock('landscape');
}