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

拥有回忆 提交于 2019-12-02 19:43:05

问题


My current attempt below

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

[{
     "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;

 }

来源:https://stackoverflow.com/questions/43563519/how-to-load-data-in-select-item-in-ionic-2-and-know-the-selected-item

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!