How to load data in select item in ionic 2 and know the selected item?


#1

i did try this solution but nothing’s showing up please i need help.!

page.html

 <form (ngSubmit)="InsertLocation()" #registerForm="ngForm">
     <ion-row>
        <ion-col>
             <img src="assets/img/1.jpg" />
              <ion-list>
                  <ion-item>
                     <ion-label>Chauffeur</ion-label>
                     <ion-select [(ngModel)]="selectedvalue"name="chauff">
   <ion-option *ngFor="let item of chauffeurs"[value]="item.nom_chauffeur">
                      {{item.nom_chauffeur}}
   </ion-option>
                     </ion-select>
                   </ion-item>
            <ion-list>
      <ion-row>
   <ion-col>
       <button ion-button class="submit-btn" type="submit" 
       [disabled]="!registerForm.form.valid">Inserer</button>
</form>

page.ts

  LoadChauffeurs(id){
  this.data.LoadChauffeur().subscribe(
      data => {
          this.chauffeurs= data;
      
             
      },
      err => {
          console.log(err);
      },
      () => console.log('success!')
  );
}

knowing the result of data is an array like this
//data [{“id_chauffeur”:6,“nom_chauffeur”:“ggg”, “num_tel”:2563,“id_chef”:10}]

and my service that i call it data in page.ts
data-service.ts

LoadChauffeur(id) {
  
  var url = 
   'http://localhost/PFEBACKEND/retrievechauffeurs.php?'key=random&id='+id;
      var response = this.http.get(url).map(res => res.json());
      return response;
       
 }

this the result i get


#2

chauffeurs = []. Initialize it to an empty array.


#4

it worked but with " id_chauffeur" wich is a number but i get the “nom_chauffeur” (string) undefined from the http call !! why is that?