1

When choosing the option, its value will be stored in a variable, how will it be get value

driver.html

 <ion-item>
    <ion-select interface = "popover">
      <ion-option *ngFor="let cg of routeData; let i = index;" value="{{i}}">{{cg.routeName}}</ion-option>
    </ion-select>
  </ion-item>

driver.ts

getRoute() {
    this.storage.get('token').then((tkn) => {
      this.headers.token = tkn;
      console.log("token Data: " + this.headers.token);
      this.driverProvider.getRoute(this.headers)
        .then(result => {
          if (JSON.parse(result.text()).response == "OK") {

            this.routeData = JSON.parse(result._body).stops;

            console.log("Route Name : " + JSON.stringify(this.routeData))  ;
          } else {
            this.err = JSON.parse(result.text()).res;
          }
        }, (err) => {
          console.log("Error is: " + err);
        });

    });

  }

output:enter image description here

Jayprakash Singh
  • 1,343
  • 3
  • 15
  • 28
  • Possible duplicate of [How to get the value from ion-select option](https://stackoverflow.com/questions/39503876/how-to-get-the-value-from-ion-select-option) – Duannx Oct 26 '17 at 02:15

1 Answers1

-1

Give ngModel to ion-select like

html

<ion-select interface = "popover">
     <ion-option *ngFor="let cg of routeData; let i = index;" value="{{i}}" (ionChange)="routeNameChanged(i,cg.routeName)">
         {{cg.routeName}}
     </ion-option>
</ion-select>

ts

export class ListPage 
{
    routeModel = "";
    constructor()
    {}
}

routeNameChanged(index,name)
{
  console.log(index+"=>"+name);
}
Paresh Gami
  • 4,777
  • 5
  • 23
  • 41