Ionic 4 LoadingController覆盖不存在 [英] Ionic 4 Loadingcontroller overlay doesnt exist

查看:28
本文介绍了Ionic 4 LoadingController覆盖不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个创建加载的简单函数,如下所示

async presentLoading() {
  const loading = await this.loadingController.create({
    message: 'Please Wait...',
  });
  await loading.present();
}

当像这样获取数据时,我将关闭加载器

  getUserData(){
  console.log(this.userID);
    this.api.getCompanyEmploye(this.userID).subscribe(res => {
     this.loadingController.dismiss(); //closing here 

      console.log(res);
      this.user = res.records[0];
      this.familyMembers = res.records[0].family_members;
    });
  }

我在构造函数中调用这两个函数

constructor(public loadingController: LoadingController){
  this.presentLoading();
  this.getUserData();
}

ERROR Error: Uncaught (in promise): overlay does not exist

的显示错误

api

问题是推荐答案调用的响应时间早于加载控制器的实例化时间。您应该尝试以这种方式序列化这些调用,而不是并行调用:

使Present Loding方法返回Promise:

async presentLoading() {
  const loading = await this.loadingController.create({
    message: 'Please Wait...',
  });
  return loading.present();
}

现在您可以这样称呼它:

getUserData(){
  this.presentLoading().then(()=>{
     this.api.getCompanyEmploye(this.userID).subscribe(res => {
        this.loadingController.dismiss(); //closing here 
        console.log(res);
        this.user = res.records[0];
        this.familyMembers = res.records[0].family_members;
    });
  })
}

在您的构造函数中,您只需调用API

这篇关于Ionic 4 LoadingController覆盖不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆