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