use ion-select dynamically

0

I've placed as options in ion-select, Zone South, North, Center and West. I want when I click on any option, only show the information of that zone taking the information from the database. At the moment I only have the same select.

<ion-item no-lines class="setaselect">
  <ion-label stacked color="carioca" >REGIÕES</ion-label>
  <ion-select>
      <ion-option value="opt1"></ion-option>
      <ion-option value="opt2">Zona Oeste</ion-option>
      <ion-option value="opt3">Zona Norte</ion-option>
      <ion-option value="opt4">Zona Sul</ion-option>

  </ion-select>

DB.ts

getRegiao(pregiao: string){
return new Promise<Regiao[]>((resolve, reject) => { 

  let sql = "select * from tb_regiao" + pregiao;
  console.log(sql);          
  this.executeQuery(sql).then(data => {
    let regioes = [];
    data.forEach(function (row) {
      let regiao: Regiao = { nom_regiao: row[0]}
      regioes.push(regiao);
    });
    resolve();

  }).catch(error => {
    console.log(error);
  });

});


}

and my ts function.

 selecionaregiao(pregiao: string) {
this.db.getRegiao(pregiao)
        .then(data => this.regioes = data)
        .catch(error => console.log('Something want wrong!'));
 }

But I do not know exactly how I do it, nor can I search exactly what I want. As I am still learning, I decided to ask for this information here: D
If anyone knows how I do this, or some tutorial, I really do not know how to search how to do this.

    
asked by anonymous 03.08.2018 / 15:24

1 answer

0

Performs a function that searches the data and does the following in its component: It creates a NgModel for your select and calls a function when changing the data.

<ion-select (ionChange)="suaFuncao()" [(ngModel)]="regiao">
      <ion-option value="opt1"></ion-option>
      <ion-option value="opt2">Zona Oeste</ion-option>
      <ion-option value="opt3">Zona Norte</ion-option>
      <ion-option value="opt4">Zona Sul</ion-option>

  </ion-select>

No typescript does:

regiao: any; //Se tiver um tipo específico coloca ele

suaFuncao(){
    //Chama a função para buscar do banco de dados e passa this.regiao como parâmetro.
}
    
03.08.2018 / 16:11