我是Ionic 4的新成员,我正在尝试将屏幕方向设置为景致,参考docs,这就是我正在做的:
...
import {ScreenOrientation} from '@ionic-native/screen-orientation';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html'
})
export class AppComponent {
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private screenOrientation: ScreenOrientation,
) {
this.initializeApp();
}
initializeApp() {
this.screenOrientation.lock(ScreenOrientation.ORIENTATIONS.LANDSCAPE);
...
}
}在编译过程中,我得到了以下错误:
src/app/app.Component.ts(24,33)中的ng错误: ERROR TS2345:类型'string‘的参数不能分配给'OrientationLockType’类型的参数。
在浏览器控制台上:
未明错误:无法解析AppComponent:(对象对象,?)的所有参数。syntaxError (compiler.js:2426) [] .
发布于 2019-01-28 10:36:18
在第四个参数的注入中有一个问题,您是否正确安装了屏幕方向插件?
ionic cordova plugin add cordova-plugin-screen-orientation
npm install @ionic-native/screen-orientationhttps://cordova.apache.org/docs/en/latest/reference/cordova-plugin-screen-orientation/
如果这不起作用,你应该试试这个方法(通过导入和注入)
cordova plugin add cordova-plugin-screen-orientationhttps://cordova.apache.org/docs/en/latest/reference/cordova-plugin-screen-orientation/
此外,如果要强制整个应用程序面向景观,则可以在config.xml中添加首选项。
<preference name="orientation" value="landscape" />我已经测试过它,它在android平台7.1.4中工作。
发布于 2019-02-27 23:50:23
你用离子V4,请看文档,导入正确的东西。
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';不
import {ScreenOrientation} from '@ionic-native/screen-orientation';发布于 2019-08-05 05:17:17
确保使用插件将ScreenOrientation添加到模块中的提供者数组中。
例如,在app.module.ts中
https://stackoverflow.com/questions/54392073
复制相似问题