javascript - 从 Ionic 4 警报中的输入中获取值

标签 javascript ionic4

截至今天,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/

相关文章:

ios - Angular Service Worker 不适用于 iOS 独立模式

javascript - 单击后导航栏中指向#anchors 的链接未关闭

javascript - 自定义着色器中的灯光位置(着色器 Material )

javascript - Highcharts:导出图表中的重叠列

ionic-framework - 我的 slider 遮流效果在 Ionic 4 中不起作用

ios - 使用 Ionic 4 在 iOS 中直接调用,无需额外对话框

javascript - 如何向我的 React 应用程序添加下拉菜单?

javascript - tsconfig 文件中存在语法错误?

angular - 如何在 ionic 4 应用程序 ion-list 上放置一个简单的过滤器

ios - Ionic 4应用程序在iOs 13上要求蓝牙许可