我正在使用离子5,并试图使用离子LoadingController与解析器。
起初,我遇到的问题是在loadingController.create()
完成之前调用了loadingController.dismiss()
,所以我按照下面的说明操作:Ionic 4: "Loading Controller" dismiss() is called before present() which will keep spinner without dismissing。
因此,我创建了一个服务来显示和关闭加载器,如下所示:
export class LoaderService {
isLoading = false;
constructor(public loadingController: LoadingController) { }
async present() {
this.isLoading = true;
return await this.loadingController.create().then(a => {
a.present().then(() => {
if (!this.isLoading) {
a.dismiss();
}
});
});
}
async dismiss() {
if (this.isLoading) {
this.isLoading = false;
return await this.loadingController.dismiss();
}
return null;
}
}
我在app.component中调用它
constructor(
private platform: Platform, private loaderService: LoaderService,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private languageService: LanguageService,
private appDataService: AppDataService,
private popOverCtrl: PopoverController,
private auth: AuthService, private router: Router
) {
this.router.events.subscribe((event: Event) => {
switch(true){
case event instanceof NavigationStart: {
this.loaderService.present();
break;
}
case event instanceof NavigationEnd:
case event instanceof NavigationCancel:
case event instanceof NavigationError: {
this.loaderService.dismiss();
break;
}
default: {
break;
}
}
})
this.initializeApp();
}
但我得到以下错误:
5条答案
按热度按时间13z8s7eq1#
izj3ouym2#
Uncaught (in promise): overlay does not exist is a very generic error and can appear in multiple situations. In general, it occurs when trying to resolve a promise and it does not exist.
The solution is quite simple, we are trying to close a modal or the loading component when it has not been created yet.
You should use the ionic lifecycle (see documentation ) to be able to initialize the LoadingController before closing it:
I hope it helps.
3okqufwl3#
Calling the loader in a timeout function solves it for me. All calls to the loader function are made from a shared service.
and ensure you check if the loader is active before closing it
j5fpnvbx4#
这也可能是由于在浏览器中运行您的应用造成的,特别是在使用浏览器设备仿真时(在Chrome中称为“设备工具栏”,在Firefox中称为“响应模式”)。请尝试禁用设备工具栏(Ctrl+Shift+M)或在物理设备上运行您的应用,或者使用适当的仿真器。
5sxhfpxr5#