我想锁定我的屏幕方向在我的ionic2应用程序的特定页面景观。因此,我也从离子站点和Cordova屏幕方向插件导入了插件:
import { ScreenOrientation } from 'ionic-native';然后我试着在我的constructor中调用它
constructor(public navCtrl: NavController,
public orientation:ScreenOrientation
) {
ScreenOrientation.lockOrientation('Landscape');
}但我发现了一个错误:
异常:./Test类Test_Host中的错误-内联模板:0:0造成的原因是:没有提供程序的ScreenOrientation!
这里似乎有什么问题?
发布于 2017-04-27 17:26:22
错误是指出ScreenOrientation“服务”没有可用的提供程序。为了使用这些提供程序,必须首先在app.module.ts中声明它们。
要将ScreenOrientation添加到app.module.ts中的提供程序列表中:
import { ScreenOrientation } from '@ionic-native/screen-orientation';providers: [ StatusBar, SplashScreen, ScreenOrientation, {provide: ErrorHandler, useClass: IonicErrorHandler} ]发布于 2016-12-31 06:12:23
从构造函数中删除参数“公共方向:屏幕导向”。
https://stackoverflow.com/questions/41405858
复制相似问题