Http Post Array in Ionic 3 - SQLite - Angular 4

This post was flagged by the community and is temporarily hidden.

Holy nesting, Batman!

So below is what I propose. First, there’s less nesting and no more nested promises :+1:. Second, I moved the POST request outside of your for loop, as it seems you want to sync all contacts at once rather than one at a time while building the array :thinking:. Third, I don’t think you need to manually convert parameters to JSON with

postRequest() {
  return this.sqlite.create({
    name: 'ionicdb.db',
    location: 'default'
  .then(db => db.executeSql('SELECT * FROM Contactos ORDER BY rowid DESC', {}))
  .then(result => {
    this.contactos = [];

    for(var i = 0; i< result.rows.length; i++) {

    var headers = new Headers();
    headers.append("Accept", 'application/json');
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    let options = new RequestOptions({ headers: headers });
    let params = { 
      nombre: 'Sergio',
      telefono: '1234567',
      ext: '000',
      correo: '',
      empresa: 'Globaltek'

    return"", params, options).toPromise();
  .then(contactos => {
    console.log(contactos ['_body']);'Datos Sincronizados!' , '4000', 'center').subscribe(toast => console.log(contactos))
  }, error => {
    console.log(error.message);// Error obteniendo los datos!'Error en la sincronizacion!'+ error.message, '4000' , 'center').subscribe(toast => console.log(toast))
  .catch(err => console.error(err));

The array:

public contactos: any [] = [];

Not Works :slightly_frowning_face: Show this message: Error en la sinicronizacion! undefined.

Bet this is s CORS Problem. Add allow origin at the server side