cordova - Ionic 4 - 屏幕方向(横向)不起作用
问题描述
我是 Ionic 4 的新手,我正在尝试将屏幕方向设置为横向并参考文档,这就是我正在做的事情:
...
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);
...
}
}
在编译期间,我收到此错误:
[ng] src/app/app.component.ts(24,33) 中的错误:错误 TS2345:“字符串”类型的参数不可分配给“方向锁定类型”类型的参数。
在浏览器控制台上:
未捕获的错误:无法解析 AppComponent 的所有参数:([object Object]、[object Object]、[object Object]、?)。在 syntaxError (compiler.js:2426) [] ...
解决方案
您使用 ionic V4,请参阅文档,导入正确的内容。
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
不是
import {ScreenOrientation} from '@ionic-native/screen-orientation';
推荐阅读
- java - 如何向用户显示电影列表,让他选择电影并将电影保存在表格中?
- swift - Thread1 -[Subject addTasksObject:]:无法识别的选择器发送到实例 0x60000293cb00'
- python - 将 Twilio 帐户添加到 whatsapp 组
- python - Python 提取两个时间戳之间的 JSON 对象模式
- javascript - 递增和递减 Firebase Ionic 5
- javascript - useState 如何遍历数组
- javascript - 变量何时相互分配的规则
- docker - 在多个 gitlab 运行器实例上创建相同的缓存
- javascript - React Hooks:加载时立即随机播放数组,然后单击
- flutter - 我想在 Flutter 中显示复杂的 JSON 数据但一无所获