[英]why this ionic alert code is not working using angular
async presentAlert() {
const alert = await this.alertController.create({
header: 'Alert',
subHeader: 'Subtitle',
message: 'This is an alert message.',
buttons: ['OK'],
});
await alert.present();
let result = await alert.onDidDismiss();
console.log(result);
}
我的 html 是
<div class="about-button">
<ion-button (click)="presentAlert()">About</ion-button>
</div>
這將如何運作? 單擊按鈕沒有任何反應,這是行不通的。 我的 ionic 版本是 5.4.5,也嘗試了 ionic 4
其實一切都是正確的。 我的 app.html 中只有 2 個 app-root。 這並不能讓它顯示出來。
我發現了這個,只使用一次等待。 您可以有一個按鈕,在警報關閉時可以處理數據。
const alert = await this.alertController.create({
inputs: [
{
name: 'name1',
type: 'text'
}],
buttons: [
{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
handler: () => {
console.log('Confirm Cancel');
}
}, {
text: 'Ok',
handler: (alertData) => { //takes the data
console.log(alertData.name1);
}
}
]
});
await alert.present();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.