【问题标题】:How to get the input value of a AlertController in Ionic如何在 Ionic 中获取 AlertController 的输入值
【发布时间】:2018-03-06 08:24:45
【问题描述】:

所以我正在尝试从 AlertController 获取输入,但我不确定如何在 Typescript 中执行此操作。

ionViewDidLoad(){
    // Presenting popup
    this.alert.create({
        title:'Enter Details',
        inputs:[{
            //phNo:'Enter Mob No. E.g.919090998302',
            //placeholder: 'pNo',
            name:'username',
            placeholder: 'username'

        },{
        name: 'number',
        placeholder: 'PNo',

      }],

        buttons:[{
            text: 'Continue',
            handler: username =>{
                if(typeof username!=null){
                this.name = username,
                this.phNo = number
                }
            }
        }]
    }).present();

我需要在单击按钮后立即获取第二个输入值,但我不知道我该怎么做,这里写着Cannot find name "number"

【问题讨论】:

    标签: typescript ionic-framework


    【解决方案1】:

    所有输入字段都传递给处理程序。如果只有一个字段,您可以立即访问它。但既然有很多领域。处理程序参数将是一个对象

    所以试试这个。

     buttons:[{
                text: 'Continue',
                handler: data =>{
                    if(typeof username!=null){
                    this.name = data.username,
                    this.phNo = data.number
                    }
                }
            }]
    

    【讨论】:

    • 您好!你知道如何设置值吗?我试过 value: 'something' 但没用
    • 没关系,其实是value属性,我只是打错了
    猜你喜欢
    • 2018-11-24
    • 1970-01-01
    • 2018-01-18
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    • 2014-11-15
    • 1970-01-01
    • 2019-10-31
    相关资源
    最近更新 更多