How to make ngFor wait for a function to finish - Ionic Angular

0

Good afternoon, I'm doing that when doing tap on a Select call a function that through http is completed an Array with the values that will then run through the * ngFor, the problem is that pressing the Select the first time does not it reaches to load the values, but in the second time that it presses it already loads the list correctly, I suppose that it is because the array that will travel the ngFor still not filled, for that reason I would like to make the ngFor wait for the function options () Is it over, how can I do it?

HTML:

<div *ngIf="item.idTipo=='7'" on-tap="opciones(item.idPregunta)">
        <ion-item class="respuesta">
                <ion-select [(ngModel)]="select" okText="Seleccionar" cancelText="Cancelar">
                    <ion-option *ngFor="let opcion of Opciones[item.idPregunta]" [value]="opcion.nombreOpcion">{{opcion.nombreOpcion}}</ion-option>
                </ion-select>     
        </ion-item>                               
 </div>

TS:

opciones(reciboidPregunta){
    //recibo el id de la pregunta para cargar las opciones asociadas
    this.opcionPost.idPregunta=reciboidPregunta;

    this.authServiceProvider.postData(this.opcionPost, 'Opciones')
    .then((result) => {
      this.responseOpcion = result;
      //array que guarda como index a el id de la pregunta
      this.Opciones[reciboidPregunta]=this.responseOpcion.opciones;

      console.log(this.Opciones);
    }, (err) => {
      console.log(err);
    });

  }
    
asked by Kako 09.12.2017 в 18:11
source

1 answer

0

I would try that the query that is launched when you do "tap" is done before, I think it would not be good for the user experience to give "tap" and have to wait for X time until "come" the data of the select, It is possible, that he is impatient and "tap" several times in a row.

Try to load that data before it's done 'tap'

    
answered by 10.12.2017 / 01:36
source