How to get the data from alert-prompt


#1

Hi,
How to get the data from alert-prompt ?


#2

Copy this example and change this line:

console.log(‘Saved clicked’);

to this one:

console.log(data);

It must work fine. The input value must be in “data.title” or “data[‘title’]”


#3

Just like you set input’s name you can access that propertie.

inputs: [
             {
                name: 'FirstName',
                placeholder: 'First Name'
             },
             {
               name: 'LastName',
               placeholder: 'Last Name'
             }
],

Get them at button handler like

buttons: [
           {
               text: 'OK',
               handler: data => {
                   console.log(JSON.stringify(data)); //to see the object
                   console.log(data.FirstName);
                   console.log(data.LastName);
               }
           }
]

#4

Hi, how can I get the result to display in html? thankyou.


#5

VALUE="{{data.FirstName }}"


#6

What is “Value” ?

<h1>{{ data.UserName }}</h1>

This code doesn’t work!

And it’s possible to show prompt data on all page of the app?


#7

in ts
declare Review: string = ’ ’ ;

rate() {

let alert = this.alertCtrl.create({
  title: 'Rate',
  buttons: [
    {
      text: '1', handler: data => {
        this.rating_no = 1; console.log(this.rating_no,
          this.Review = JSON.stringify(data.Review));
      }
    }
  ],
  inputs: [
    {
      name: 'Review',
      placeholder: 'Write a review',
    },
  ],
  cssClass: 'alertstar',
  enableBackdropDismiss: false
});
alert.present();
console.log(this.Review); 

}

in html

{{this.Review}}

Review is the iput name where JSON data is changed into string by stringify(data.Review).
store in db or declare globally to show the value in all pages,this is to get the rating number and review text