Thursday, June 6, 2024
 Popular · Latest · Hot · Upcoming
60
rated 0 times [  64] [ 4]  / answers: 1 / hits: 22294  / 5 Years ago, fri, april 5, 2019, 12:00:00

As of today the Ionic 4 documentation on ion-alert contains an example how to add a text input to an alert, like this:



const alert = await this.alertController.create({
inputs: [
{
name: 'name1',
type: 'text'
},


But I can not find out how to access the value from the name1 text input, for example in the button handlers.



Do I have to use something like document.getElementById or is there a more Ionic/Angular-style way?


More From » ionic4

 Answers
17

you can have a button that on the close of the alert can handle the data.


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();

[#52299] Saturday, March 30, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaitlyn

Total Points: 421
Total Questions: 73
Total Answers: 100

Location: South Georgia
Member since Sat, Jul 25, 2020
4 Years ago
kaitlyn questions
Mon, Jan 10, 22, 00:00, 2 Years ago
Wed, Jun 2, 21, 00:00, 3 Years ago
Wed, Jan 20, 21, 00:00, 3 Years ago
Mon, Dec 2, 19, 00:00, 5 Years ago
;