我使用了"Ionic Loading Controller"来展示一个旋转图标,直到数据被检索出来然后调用"dismiss()"方法来关闭它。 它运行良好,但有时候当应用已经有了数据时,"dismiss()"方法会在"create()"和"present()"方法完成之前被调用,这将导致旋转图标无法关闭...
我尝试在"loadingController.present().then()"中调用数据,但这会使数据变慢...
这是一个bug吗? 如何解决这个问题?
我的代码示例:
customer: any;
constructor(public loadingController: LoadingController, private customerService: CustomerService)
ngOnInit() {
this.presentLoading().then(a => consloe.log('presented'));
this.customerService.getCustomer('1')
.subscribe(customer => {
this.customer = customer;
this.loadingController.dismiss().then(a => console.log('dismissed'));
}
}
async presentLoading() {
const loading = await this.loadingController.create({
message: 'wait. . .',
duration: 5000
});
return await loading.present();
}