Ionic framework await与模态控制器在ionic 6中的应用
将等待用作Ionic framework await与模态控制器在ionic 6中的应用,ionic-framework,Ionic Framework,将等待用作 return await modal.present(); 然后将数据作为 const { data } = await modal.onWillDismiss(); 然而,上述方法对我来说并不奏效,尤其是在取回数据时。我得到的错误onwilldismission'在类型“Promise”上不存在。对我来说,ondiddisclease也是如此 以下是我的作品,我必须使用await(await模式)。。我是错过了什么还是做错了什么 async presentModal(){
return await modal.present();
然后将数据作为
const { data } = await modal.onWillDismiss();
然而,上述方法对我来说并不奏效,尤其是在取回数据时。我得到的错误onwilldismission'在类型“Promise”上不存在
。对我来说,ondiddisclease
也是如此
以下是我的作品,我必须使用await(await模式)。
。我是错过了什么还是做错了什么
async presentModal(){
let modal = this.modalCntrl.create({
component: CreateTestModalComponent,
componentProps: { selectedName: this.name }, //gets passed in as the INPUT property
keyboardClose: true,
swipeToClose: true
});
await (await modal).present();
const { data, role } = await (await modal).onWillDismiss(); //onDidDismiss()
if(role === "confirm"){
this.presentAlert(`Message passed back<br/><br/>${data.message}<br/><br/>Role '${role}' passed back`);
}
else{
this.presentAlert(`Cancel clicked!<br/><br/>Role '${role}' passed back`);
}
}
async presentAlert(message: string){
const alert = await this.alertCntrl.create({
header: 'Alert',
message: message,
buttons: ['Ok']
});
await alert.present();
}
async presentModal(){
让modal=this.modalCntrl.create({
组件:CreateTestModalComponent,
componentProps:{selectedName:this.name},//作为输入属性传入
键盘关闭:对,
swipeToClose:对
});
等待(等待模态).present();
const{data,role}=await(await modal).onwilldisease();//ondiddeslish()
如果(角色==“确认”){
此.presentAlert(`Message passed back
${data.Message}
Role'${Role}'passed back`);
}
否则{
this.presentAlert(`Cancel clicked!
Role'${Role}'传回`);
}
}
异步presentAlert(消息:字符串){
const alert=等待this.alertCntrl.create({
标题:“警报”,
讯息:讯息,,
按钮:[“确定”]
});
等待警报。当前();
}
我想再澄清一件事,警报显示存在滞后。使用onwilldisease()
时,警报显示速度比ondiddisease()
快得多/早得多
我刚刚接触爱奥尼亚6,现在正在学习,因此出现了上述问题/困惑
节点:v14.15.5
npm:v6.14.11
ng:v11.2.0
爱奥尼亚:v6.13.1异步呈现模式(){
async presentModal(){
const modal = await this.modalCtrl.create({keep ur props the same..});
modal.present();
// now here there should be no errors from above side after we put aeait before modal create
const { data, role } = await modal.onWillDismiss();
if(role === "confirm"){
this.presentAlert(`Message passed back<br/><br/>${data.message}<br/><br/>Role '${role}' passed back`);
}
else{
this.presentAlert(`Cancel clicked!<br/><br/>Role '${role}' passed back`);
}
}
const modal=wait this.modalCtrl.create({保持你的道具不变..});
情态动词present();
//现在,在我们把aeait放在模态创建之前,上面应该并没有错误
const{data,role}=await modal.onwilldisease();
如果(角色==“确认”){
此.presentAlert(`Message passed back
${data.Message}
Role'${Role}'passed back`);
}
否则{
this.presentAlert(`Cancel clicked!
Role'${Role}'传回`);
}
}
u问题就在这里:wait(wait modal)只是不需要对wait进行等待,因为它总是会导致错误,只需执行wait modal.present();或者等待modal.onwilldisease();我也在指出同样的事情。文档还说使用wait modal.present()代码>和等待模态.onwilldisease()代码>。当使用这个时,我得到一个错误。我能消除错误的唯一方法是使用const{data,role}=await(await modal).onwilldisease()代码>.Ok语句的开头是错误的,让modal=this.modal。。。是错误的,我将在下面写下答案,你是正确的,应该是let modal=wait this.modalCntrl.create(