Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework 离子4加载控制器覆盖不存在_Ionic Framework_Ionic4 - Fatal编程技术网

Ionic framework 离子4加载控制器覆盖不存在

Ionic framework 离子4加载控制器覆盖不存在,ionic-framework,ionic4,Ionic Framework,Ionic4,我创建了一个简单的函数来创建这样的加载 async presentLoading() { const loading = await this.loadingController.create({ message: 'Please Wait...', }); await loading.present(); } getUserData(){ console.log(this.userID); this.api.getCompanyEmploye(this.u

我创建了一个简单的函数来创建这样的加载

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;
    });
  }
当数据被这样提取时,我关闭加载程序

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();
}

它的显示错误为:Uncaught(承诺中):覆盖不存在

问题是API调用的响应速度比加载控制器的实例化速度要快。您应该尝试通过以下方式序列化这些调用,而不是并行调用:

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;
    });
  })
}
让您的当前加载方法返回承诺:

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就可以了,不知道为什么文档使用异步等待样式。它实际上会让任何新来的人感到困惑。哈哈