截至今天,ion-alert 上的 Ionic 4 文档包含如何将文本输入添加到警报的示例,如下所示:
const alert = await this.alertController.create({
inputs: [
{
name: 'name1',
type: 'text'
},
但我不知道如何访问
name1
中的值文本输入,例如在按钮处理程序中。我必须使用
document.getElementById
之类的东西吗?还是有更 ionic /Angular 风格的方式?
最佳答案
您可以有一个按钮,在警报关闭时可以处理数据。
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();
关于javascript - 从 Ionic 4 警报中的输入中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55540312/