How to get the input value of a AlertController in Ionic

Viewed 5320

So I'm trying to get input from an AlertController, and I'm not sure how to do that in 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();

I need to get the second input value as soon as I click the button, but I'm not sure how do I do that in this, in this it says Cannot find name "number".

1 Answers

all the input fields are passed to the handler. if theres only one field, you can access it straight away. but since there are many fields . handler params will be an object

so try this.

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