【发布时间】:2016-12-31 05:50:54
【问题描述】:
我想在我的ionic2 应用程序的特定页面上将屏幕方向锁定为横向。所以我从离子站点导入the plugin 和Cordova 屏幕方向plugin:
import { ScreenOrientation } from 'ionic-native';
然后我尝试在我的constructor 中调用它:
constructor(public navCtrl: NavController,
public orientation:ScreenOrientation
) {
ScreenOrientation.lockOrientation('Landscape');
}
但是我收到了这个错误:
异常:./Test 类 Test_Host 中的错误 - 内联模板:0:0 原因:没有 ScreenOrientation 的提供者!
这似乎是什么问题?
【问题讨论】:
-
构造函数用于提供者的依赖注入..插件通过全局对象访问..
-
我应该在哪里调用函数
ScreenOrientation.lockOrientation('Landscape');?我尝试了很多地方,它给了我编译警告。 -
警告是什么?通常你将插件的构造函数放在`this.platform.ready