How do I get the textfield value from a ionic2 framework alert box?
<ion-item ('click')="enterPwd();">Admin</ion-item>
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.