# List does not update

**URL:** <https://forum.ionicframework.com/t/list-does-not-update/80416>\
**Category:** tutorials\
**Created:** [February 21, 2017, 3:40pm UTC](https://forum.ionicframework.com/t/list-does-not-update/80416 "2017-02-21T15:40:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Claumir](https://avatars.discourse-cdn.com/v4/letter/c/f1d935/32.png) [@Claumir](https://forum.ionicframework.com/u/Claumir)\
**Post date:** [February 21, 2017, 3:40pm UTC](https://forum.ionicframework.com/t/list-does-not-update/80416/1 "2017-02-21T15:40:15Z")

</div>

Good morning, I’m starting my ionic journey and I have the following scenario:  
I created an app, a simple CRUD, where you have a list of items and a modal to register a new item, when I close the modal clicking save the new item is sent to my API, saved in the database and returned to the list. This works fine in the ionic serve but when I squeeze in the device the item just saves in the bank but does not return to list. My Class Functions:

```
 getDados() {
  //retorno de Dados
   this.service.getData()
    this.service.getData()
      .then((lancamentos: Array<any>) => {
        this.lancamentos = lancamentos;
      }, (error) => {
        console.log('Erro ao listar ',error);
      })
  }

  postDados(lancamento) {
    this.service.postData(lancamento.value)
      .then((data) => {
        if(data) {
          console.log(data),
          this.close();  
          this.presentToast();
        }
      }, (error) => {
          console.log('Erro ao cadastrar. ', error);
          this.presentToastErro();
      }
    );
  }

```

minhas funções provider para API:

```
  getData() {
        return new Promise((resolve, reject) => {
              this.http.get(this.api + 'apiRecupera.php')
              .map(res => res.json())
              .subscribe(data => {
                    resolve(data);
              }, error => {
                    reject(error);
              });
        });
        
  }

  postData(parans) {
        let headers = new Headers({ 'Content-Type' : 'application/x-www-form-urlencoded' });

        return new Promise((resolve, reject) => {
              this.http.post(this.api + "apiCadastroCont.php", JSON.stringify(parans), {
              headers:headers,
              method:"POST"
        })
        .map(res => res.json())
        .subscribe(data => {
              resolve(data);
        }, error => {
              reject(error);
        })
    });     
  }`Preformatted text`
```

---

<div class="post-metadata">

**Author:** ![rickdana](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rickdana/32/107112_2.png) [@rickdana](https://forum.ionicframework.com/u/rickdana)\
**Post date:** [February 21, 2017, 4:21pm UTC](https://forum.ionicframework.com/t/list-does-not-update/80416/2 "2017-02-21T16:21:04Z")

</div>

Since I can see your component class it is difficult for me to troubleshot what is going on. I Suggest you use the chrome/safari remote debugger to look what is going wrong. [here](https://ionicframework.com/docs/v2/resources/developer-tips/) you can see how to do that.

---

<div class="post-metadata">

**Author:** ![Claumir](https://avatars.discourse-cdn.com/v4/letter/c/f1d935/32.png) [@Claumir](https://forum.ionicframework.com/u/Claumir)\
**Post date:** [February 21, 2017, 5:01pm UTC](https://forum.ionicframework.com/t/list-does-not-update/80416/3 "2017-02-21T17:01:29Z")

</div>

Thanks for the reply, the big problem is that it does not present me any errors in the debugger, in console me diz the message that the operation in the database worked out (really works) just does not update the list of items. Just refresh if I go into the app settings and clear the data.

My service:

```
import { Injectable } from '@angular/core';
import { Http, Headers, Response, ResponseOptions } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';

@Injectable()
export class ServiceProvider {

      api : string = 'myUrl';

  constructor(public http: Http) {}

  
      getData() {
            return new Promise((resolve, reject) => {
                  this.http.get(this.api + 'apiRecupera.php')
                  .map(res => res.json())
                  .subscribe(data => {
                        resolve(data);
                  }, error => {
                        reject(error);
                  });
            });
            
      }

      postData(parans) {
            let headers = new Headers({ 'Content-Type' : 'application/x-www-form-urlencoded' });

            return new Promise((resolve, reject) => {
                  this.http.post(this.api + "apiCadastroCont.php", JSON.stringify(parans), {
                  headers:headers,
                  method:"POST"
            })
            .map(res => res.json())
            .subscribe(data => {
                  resolve(data);
            }, error => {
                  reject(error);
            })
        });     
      }

      deleteData(id) {
            let headers = new Headers({ 'Content-Type' : 'application/x-www-form-urlencoded' });

            return new Promise((resolve, reject) => {
                  this.http.patch(this.api + "apiDeleta.php", id, {
                  headers:headers,
                  method: "PATCH"
             })
                  .map(res => res.json())
                  .subscribe(data => {
                        resolve(data);
                  }, error => {
                        reject(error);
                  });
            });
      }
      
      updateData(data) {
            let headers = new Headers({ 'Content-Type' : 'application/x-www-form-urlencoded' });

            return new Promise((resolve, reject) => {
                  this.http.post(this.api + "apiUpdate.php", data, {
                  headers:headers,
                  method:"POST"
            })
                  .map(res => res.json())
                  .subscribe(data => {
                        resolve(data);
                  }, error => {
                        reject(error);
                  });
            });
      }

}

```

My component:

```
import { Component, OnInit } from '@angular/core';
import { NavController, NavParams, ViewController, ToastController } from 'ionic-angular';
import { Camera } from 'ionic-native';
import { NgForm } from '@angular/forms';
import { ServiceProvider } from '../../providers/service-provider';

@Component({
  selector: 'page-modal-lancamentos',
  templateUrl: 'modal-lancamentos.html'
})
export class ModalLancamentosPage implements OnInit {

  lancamentos: any;
  image: any;

  constructor(public navCtrl: NavController, public service : ServiceProvider, 
              public navParams: NavParams, public view: ViewController,
              public toastCtrl: ToastController ) {

                this.lancamentos = {};
              }

  presentToast() {
    let toast = this.toastCtrl.create({
      message: 'Lançamento salvo!',
      duration: 2000
    });
    toast.present();
  }

  presentToastErro() {
    let toast = this.toastCtrl.create({
      message: 'Erro ao enviar lançamento, tente mais tarde!',
      duration: 2000
    });
    toast.present();
  }

  getDados() {
  //retorno de Dados
   this.service.getData()
    this.service.getData()
      .then((lancamentos: Array<any>) => {
        this.lancamentos = lancamentos;
      }, (error) => {
        console.log('Erro ao listar ',error);
      })
  }

  postDados(lancamento) {
    this.service.postData(lancamento.value)
      .then((data) => {
        if(data) {
          console.log(data),
          this.close();  
          this.presentToast();
        }
      }, (error) => {
          console.log('Erro ao cadastrar. ', error);
          this.presentToastErro();
      }
    );
  }

  ngOnInit() {

  }

  close() {
    this.view.dismiss(this.lancamentos);
  }

  takeComprovante() {

    Camera.getPicture({
      allowEdit: true
    }).then((imageData) => {
          let base64Image = 'data:image/jpeg;base64,' + imageData;
          this.image = base64Image;
      }, (err) => {
        console.log(err);
    });

  }

}
```

---

<div class="post-metadata">

**Author:** ![rickdana](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rickdana/32/107112_2.png) [@rickdana](https://forum.ionicframework.com/u/rickdana)\
**Post date:** [February 22, 2017, 12:55pm UTC](https://forum.ionicframework.com/t/list-does-not-update/80416/4 "2017-02-22T12:55:37Z")

</div>

for what I’ve understood, you have a page that open a modal to created a new object (lancamentos).  
after the form complete you call the WS postDados() . and then you dismiss the modal by passing the data (response of the post).

What I think in other to update you list after the modal closed, you need to call the onDismiss method of your modal in the list page class

```
 ModalLancamentosPage.onDidDismiss(data => {
         console.log(data);
          // do some stuff whit data 
   });
```

---

<div class="post-metadata">

**Author:** ![rickdana](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rickdana/32/107112_2.png) [@rickdana](https://forum.ionicframework.com/u/rickdana)\
**Post date:** [February 22, 2017, 1:58pm UTC](https://forum.ionicframework.com/t/list-does-not-update/80416/5 "2017-02-22T13:58:01Z")

</div>

I suggest you read this to

> [@Ionic Modal don't return data. How to return data from ionic modals?](https://forum.ionicframework.com/t/ionic-2-modal-dont-return-data-how-to-return-data-from-ionic-2-modals/47787/5):
>
> You need to add a handler for modal’s onDismiss() and then return the data from the modal itself by passing the data to the ViewController’s dismiss() method: // myPage.ts // Passing data to the modal: let modal = Modal.create(myModal, { data: [...] }); // Getting data from the modal: modal.onDismiss(data =\> { console.log('MODAL DATA', data); }); this.nav.present(modal); // myModal.ts constructor(inputData: NavParams, private view: ViewController) { // Getting data from the page: …

---

<div class="post-metadata">

**Author:** ![Claumir](https://avatars.discourse-cdn.com/v4/letter/c/f1d935/32.png) [@Claumir](https://forum.ionicframework.com/u/Claumir)\
**Post date:** [February 22, 2017, 2:30pm UTC](https://forum.ionicframework.com/t/list-does-not-update/80416/6 "2017-02-22T14:30:45Z")

</div>

Sorry it does not appear in the code, but I already do it this way:

```
presentModalLancar(){
    let modalLancar = this.modalCtrl.create(ModalLancamentosPage);

    modalLancar.onDidDismiss(() => {
        this.getDados();
    }); 

    modalLancar.present();
  }

```

Even without success

---

<div class="post-metadata">

**Author:** ![rickdana](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rickdana/32/107112_2.png) [@rickdana](https://forum.ionicframework.com/u/rickdana)\
**Post date:** [February 22, 2017, 2:35pm UTC](https://forum.ionicframework.com/t/list-does-not-update/80416/7 "2017-02-22T14:35:40Z")

</div>

```
presentModalLancar(){
    let modalLancar = this.modalCtrl.create(ModalLancamentosPage);

    modalLancar.onDidDismiss((data) => {
        // try to see if this part is realy run ...
        this.getDados();
    }); 

    modalLancar.present();
  }
```

---

<div class="post-metadata">

**Author:** ![Claumir](https://avatars.discourse-cdn.com/v4/letter/c/f1d935/32.png) [@Claumir](https://forum.ionicframework.com/u/Claumir)\
**Post date:** [February 22, 2017, 5:39pm UTC](https://forum.ionicframework.com/t/list-does-not-update/80416/8 "2017-02-22T17:39:14Z")

</div>

I made a console.log inside that block and passed.

---

<div class="post-metadata">

**Author:** ![Claumir](https://avatars.discourse-cdn.com/v4/letter/c/f1d935/32.png) [@Claumir](https://forum.ionicframework.com/u/Claumir)\
**Post date:** [March 10, 2017, 2:23pm UTC](https://forum.ionicframework.com/t/list-does-not-update/80416/9 "2017-03-10T14:23:08Z")

</div>

It seems that it was some problem with the life cycle, I used the ionviewdidenter and the part of the code was solved, now I have problems in the webservice, but that’s another case. Thank you very much for the answers and all the help.
