简体   繁体   中英

How to get a textfield value from a ionic2 framework alert box?

How do I get the textfield value from a ionic2 framework alert box?

alert.html

 <ion-item ('click')="enterPwd();">Admin</ion-item>

alert.ts

enterPwd() { 
    let alert = this.alertCtrl.create({
        title: 'Enter 4 digit PIN',
        inputs: [{name:'PIN',placeholder:'pin',type:'password'}],
        buttons: [{
            text:'Done',
            type:'button-positive',
            handler: data => {
                console.log('Done clicked');
                //pin entered should be displayed in console.. 
            }
        }]
    });
    alert.present();
}

When an item is clicked, enterPwd will be called, showing the alert. When the user enters their PIN, I wish it to display in the console.

You need to set the name of the text input and access with it. Your inputs is:

`inputs:[{name:'PIN',placeholder:'pin',type:'password'}`],

In your handler,

handler: data => {
                console.log('Done clicked');
               //TO DISPLAY PIN
                console.log(data['PIN']); 
                }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM