[英]alert controller setmessage not working in ionic 4
在alertController中,如果輸入字段為空,我想調用hint.setMessage(),但這在ionic4中無效
碼
const prompt= await this.alertController.create({
header: 'insert text',
message: 'enter text',
inputs: [
{
name: 'itemtext',
placeholder: 'enter text'
}
],
buttons: [{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
handler: (blah) => {
console.log('Confirm Cancel: blah');
}
}, {
text: 'Ok',
handler: async (data:any) => {
if(data.itemtext==""){
prompt.setMessage("text should not be empty");
return false;
}
else{
console.log("data.itemtext");
}
}
}
]
});
await prompt.present();
如果文本為空,我也不想關閉警報提示,請幫忙。
您不再擁有Ionic 4中的方法,但仍可以直接更改message屬性以實現所需的功能:
const prompt= await this.alertController.create({
header: 'insert text',
message: 'enter text',
inputs: [
{
name: 'itemtext',
placeholder: 'enter text'
}
],
buttons: [{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
handler: (blah) => {
console.log('Confirm Cancel: blah');
}
}, {
text: 'Ok',
handler: (data:any) => {
if(data.itemtext==""){
prompt.message = "text should not be empty";
return false;
}
else{
console.log(data.itemtext);
}
}
}
]
});
await prompt.present();
我還從處理程序中的方法中刪除了“異步”,因為您在那里不需要它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.