Angular 使用Ionic3时出现获取不支持的错误
我拼命想抓住这个错误。 在桌面上,此代码会引发此Angular 使用Ionic3时出现获取不支持的错误,angular,ionic3,Angular,Ionic3,我拼命想抓住这个错误。 在桌面上,此代码会引发此不支持的错误: 我通常在chrome上调试 代码如下: import {Component} from "@angular/core"; import {ScreenOrientation} from "@ionic-native/screen-orientation"; @IonicPage() @Component({ selector: 'page-loading', templateUrl: 'page-loading.html
不支持的错误:
我通常在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')
}
}
}
您可以创建一个类来模拟本机类,如文档中所述
在ngModule
的提供者列表中,提到它应该使用模拟类而不是实际的本机类
providers: [..
{ provide: ScreenOrientation, useClass: ScreenOrientationMock }
]
这将返回您在resolve
中为期间的屏幕方向设置的内容
在设备中运行后,可以将其删除
编辑:
还有另一种抑制错误的可能性,因此最终您将无事可做:
if(this.platform.is('cordova')){
this.platform.ready().then(()=>{
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
})
}
ionic native或cordova不适用于ionic serve。。我知道,你只需要在一个设备或模拟器中运行,但对于其他没有问题的插件,他们抱怨沉默。我只是想在我的桌面上消除这个错误,但是try catch没有帮助哦,你是说在ionic view屏幕上?不,我用的是ionic serve,就像你说的,我只是不知道为什么我可以捕捉到这些错误一旦它在设备中运行就将其删除。
你的意思是我们以后必须手动更改代码,以便在部署应用程序时提供真正的类而不是模拟?或者有没有办法检测您正在运行的设备并自动提供模拟?嗨,不,事实上,您不应该在最后使用任何模拟。我更新response@DavidF. 谢谢不过,你本可以把它添加为自己的答案
if(this.platform.is('cordova')){
this.platform.ready().then(()=>{
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
})
}