I have a problem with an ionic3 app I'm been developing. With my app I conect to a JSON server and download a lot of rows, when I have all rows with a for, in each row call to funcion to insert data. but I think, my for is faster than insert funcion and show finalice alert before end. this is my code:
 private downloadRows()
 {
this.platform.ready().then(()=>{
   this.translateService.get('ACTUALIZANDOBARRANCOS').subscribe(
    value => {
    let loadingContent = value; 
    let loader = this.loadingController.create({
    content: loadingContent,
    spinner: "bubbles"
    });  
    this.servicioDownloads.downloadAllRows().then(rows=> {
        this.datosrows= rows;
        loader.present();
        for (var i = 0; i < this.datosrows.length; i++)
        {
          var datos = this.datosrows[i];
          // we are going to insert rows
          this.servicioDataBase.insertRow
          ( datos.indice,
            datos.row1, 
            datos.row2,
            datos.row3, 
            datos.row4, 
            datos.row5,
            datos.row6, 
            datos.row7, 
            datos.row8, 
            datos.row9, 
            datos.row10, 
            //...
            datos.row30
          ).catch(()=>{
            console.log("da error");
          });
        }
        loader.dismiss();
        this.translateService.get('FINALIZADO').subscribe(
              Titulo =>{
                  let titulo = Titulo;
               this.translateService.get('BARRANCOSACTUALIZADOS').subscribe(
                    Descripcion =>{
                      let descripcion = Descripcion;
                      let alerta = this.alertCtrl.create({
                        title: titulo,
                        subTitle: descripcion,
                        buttons: ['OK']
                      })
                      alerta.present();
                    }
                  );
              }
            );
  }).catch(error=>{
    loader.dismiss();
        this.translateService.get('ERROR').subscribe(
              Titulo =>{
                  let titulo = Titulo;
  this.translateService.get('ERRORDESCARGABARRANCOS').subscribe(
                    Descripcion =>{
                      let descripcion = Descripcion;
                      let alerta = this.alertCtrl.create({
                        title: titulo,
                        subTitle: descripcion,
                        buttons: ['OK']
                      })
                      alerta.present();
                    }
                  );
              }
        );
  })
});
})
}
//This is insert services
public insertRow( indice: any, row1: any, row2: any,  row3: any,  row4: any, 
  row5: any,  row6: any,   row7: any,   row8: any,   row9: any,  row10: any, 
  row30: any)
 {    
  let sql = "INSERT INTO TableRows (id,Nombre,Rio,Pais,Comunidad, 
  Zona,Localidad,Interes,Caracter,Cascada_max,Cuerda_max,Desnivel, 
  Longitud, Tiempo_aprox,Tiempo_descenso,Tiempo_retorno,Observaciones, 
  Descripcion_barranco,Periodo_optimo,Caudal,Caudal_filtro,Aproximacion, 
  Retorno,Loc_entrada_barranco,Loc_salida_barranco,Loc_entrada_parking, 
  Loc_salida_parking,Autor,Actualizacion,Idioma,Visible) 
  VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  console.log(sql); 
  return this.isReady()
  .then(()=>{
      return this.database.executeSql(sql, 
            [indice,BARRANCO, RIO, PAIS,COMUNIDAD,
              ZONA,LOCALIDAD,INTERES,CARACTER, CASCADA_MAX, 
              CUERDA_MAX,DESNIVEL,LONGITUD,TIEMPO_APROX,
              TIEMPO_DESCENSO,TIEMPO_RETORNO, OBSERVACIONES, 
              DESCRIPCION_BARRANCO,PERIODO_OPTIMO,CAUDAL,
              CAUDAL_FILTRO,APROXIMACION, RETORNO,
              LOC_ENTRADA_BARRANCO,LOC_SALIDA_BARRANCO, 
              LOC_ENTRADA_PARKING, LOC_SALIDA_PARKING, 
              AUTOR,actualización,idioma, visible]);
  }).then((data)=>{
    console.log("El insert devuelve esto " + JSON.stringify(data));
  })        
}
Somebody knows how can I do on time, I mean insert when for ends?
thanks a lot!
 
     
    