我勒死是为了能抓到这个错误。在桌面上,此代码将引发此NotSupportedError。

我通常在铬上调试。
以下是代码:
import {Component} from "@angular/core";
import {ScreenOrientation} from "@ionic-native/screen-orientation";
@IonicPage()
@Component({
selector: 'page-loading',
templateUrl: 'page-loading.html',
})
export class PageLoading {
constructor(private screenOrientation:ScreenOrientation) {}
ionViewDidLoad() {
console.log('ionViewDidLoad PageLoading');
try{
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT).then(()=>{
console.log('lock');
});
}catch(e){
console.warn('No cordova.js')
}
}
}发布于 2017-05-15 12:30:32
您可以创建一个类来模拟在docs 这里中描述的离子本机类。
class ScreenOrientationMock extends ScreenOrientation {
lock(type) {
return new Promise((resolve, reject) => {
resolve("locked");
})
}
}在ngModule中的提供者列表中,它应该使用模拟类而不是实际的离子本机类。
providers: [..
{ provide: ScreenOrientation, useClass: ScreenOrientationMock }
]这将返回您在resolve中为ionic serve期间的屏幕定向设置的任何内容。
一旦它在设备中运行,您就可以删除它。
编辑:
还有另一种抑制错误的可能性,所以在结束时您将没有什么可做的:
if(this.platform.is('cordova')){
this.platform.ready().then(()=>{
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
})
}https://stackoverflow.com/questions/43978662
复制相似问题