[英]Getting Not Supported Error while using Ionic3
我扼杀了能够捕捉到这个错误。 在桌面上,此代码引发此NotSupportedError
:
我通常在 chrome 上调试。
这是代码:
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')
}
}
}
你可以创建一个类的文档中描述嘲笑离子本地类在这里。
class ScreenOrientationMock extends ScreenOrientation {
lock(type) {
return new Promise((resolve, reject) => {
resolve("locked");
})
}
}
在ngModule
的提供者列表中提到它应该使用你的ngModule
类而不是实际的离子原生类。
providers: [..
{ provide: ScreenOrientation, useClass: ScreenOrientationMock }
]
这将返回无论你在已设置resolve
为screenorientation期间ionic serve
。
一旦它在设备中运行,您就可以将其删除。
编辑:
还有另一种可能性可以抑制您的错误,因此您最终将无事可做:
if(this.platform.is('cordova')){
this.platform.ready().then(()=>{
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.