soo*_*oon 3 cordova ionic2 angular
我想将我的屏幕方向锁定在ionic2应用程序中特定页面的横向.于是我进口插件从离子部位和Cordova屏幕方向插件太:
import { ScreenOrientation } from 'ionic-native';
Run Code Online (Sandbox Code Playgroud)
然后我尝试在我的电话中调用它constructor:
constructor(public navCtrl: NavController,
public orientation:ScreenOrientation
) {
ScreenOrientation.lockOrientation('Landscape');
}
Run Code Online (Sandbox Code Playgroud)
但我得到了这个错误:
例外:./Test类中的错误Test_Host - 内联模板:0:0引起:没有ScreenOrientation的提供者!
这里似乎有什么问题?
该错误表明ScreenOrientation"service"没有可用的提供程序.为了使用这些提供者,必须首先在app.module.ts中声明它们.
要将ScreenOrientation添加到app.module.ts中的提供者列表中:
首先添加导入:
import { ScreenOrientation } from '@ionic-native/screen-orientation';
然后将ScreenOrientation添加到@NgModule中的提供程序列表中:
providers: [
StatusBar,
SplashScreen,
ScreenOrientation,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
| 归档时间: |
|
| 查看次数: |
2577 次 |
| 最近记录: |