Ionic 3 + sqlite - modal onDidDismiss not returning data

Hi, i need some help!
On my modal i insert data on a child table, the insert is success.
But when i close my modal on event onDidDismiss of the modal i calculate the data that i insert in the modal but the data seems not insert yet but on the app with the modal closed the data was successful inserted.

If i close and open the modal the data that was insert first time i open the modal is there and work. But in the same time that i close the modal and try to select the inserted data on the event onDidDismiss the data is not there yet.

Some idea ?
What can i do ?

Please someone ? I really need to solve this

Please post the code that doesn’t work.
Otherwise it’s impossible to help you.

1 Like


//---begin modal----

  modalItensVenda(id: number, vendido: string = null) {
    const modalOptions: ModalOptions = {
      showBackdrop: false,
      enableBackdropDismiss: false,
      cssClass: "modalCSS"
      // enterAnimation: 'modal-alert-pop-in',
      // leaveAnimation: 'modal-alert-pop-out'

    const modalItensVenda: Modal = this.modalCtrl.create(ModalItensVendaPage, { produto: id, vendido: vendido }, modalOptions);

    modalItensVenda.onWillDismiss((data) => {
      console.log('aqui vai fechar')

    modalItensVenda.onDidDismiss((data) => {
      console.log('aqui o modal já fechou')


//----- end of modal -------

The problem is: I have a page and i call this modal, the modal has a insert in the sqlite database, the insert work ok but on the event “onDidDismiss” of this modal I call two methods and this methods check the insert I did before to calculate some fields, but the select does’t return any data, but if I open and close the modal again the data i inserted the first time i opened the modal is there and the select return ok.
But I need this data on this event “onDidDismiss”.
I try to call the methods in the “ionDidEnter” event of the screen i call the modal but does’t work too.

I will try to explain with this screenshots:

The other two screenshots:

Anyone can help me with this ?

Anyone can help me with this ?

can you post the code for this page?

Ive been working with Ionic v4 now but, if remember correctly, it should implement ViewController to call the ViewController.dismiss(data) on the code that executes on your ‘OK’ button. Then the onDidDismiss() should catch that data

advanced ModalController usage

Does’t work! I already use the viewController please help me.

  constructor(private navCtrl: NavController,
              private toast: ToastController,
              private productProvider: ProductProvider,
              private itensVendaProvider: ItensVendaProvider,
              private navParams: NavParams,
              private view: ViewController,
              private alertCtrl: AlertController,
              private photoViewer: PhotoViewer) {

      this.parIdVenda =;
      this.parIdProduto =;
      this.parIdTabelaPreco =;
      this.parVendido =;

      this.itensVenda = new ItensVenda();
      this.produto = new Produto();

      if (this.parIdProduto) {
        this.id_produto = this.parIdProduto;
          .then((result: any) => {
            this.product = result;

      if (this.parIdProduto) {
          .then((result: any) => {
            this.produto = result;

      if (this.parIdVenda) {
        this.itensVenda.id_venda = this.parIdVenda;

      if (this.parIdTabelaPreco) {      
        this.itensVenda.id_tabela_preco = this.parIdTabelaPreco;

      this.itensVendaProvider.getItem(this.itensVenda.id_venda, this.id_produto, this.parIdTabelaPreco)
        .then((result: any[]) => {
            this.itensVendaValida = result;
            if(this.itensVendaValida.length > 0){
              this.parVendido = 'S';
              this.parVendido = 'N';



Does’t work! I already use the viewController please help me.

You have to pass some data in this.view.dismiss() to get it back in onDidDismiss(data)

I try and have the same problem … the method “this.calculaVenda();” doesn’t recognize that i inserted the item on the modal … but if i open the modal and close again the sum() in this method works ok

I don’t understand your answer.
calculaVenda() is only executed when you dismiss the modal, so it seems to do that.
Where does the problem lie then?

Yes the method executed correctly, but like i said in the modal i insert that with this method:

    if (this.itensVenda.qt_item == 0){
      this.itensVendaProvider.remove(this.itensVenda.id_venda, this.itensVenda.id_produto, this.itensVenda.id_tabela_preco);
    else if (this.itensVenda.qt_item > 0 && this.itensVenda.qt_item % this.produto.qt_multiplo > 0){
      this.toast.create({ message: 'Quantidade do Item inválida, não é múltiplo de: '+this.produto.qt_multiplo.toString()+'.', duration: 2000, position: 'botton' }).present();
      if (this.parVendido == 'S'){
        this.itensVenda.vendido = 'S';

This method in the modal call my provider itensVendaProvider to insert data:

export class ItensVendaProvider {

  constructor(private dbProvider: DatabaseProvider) { }

  public insert(itemVenda: ItensVenda) {
    return this.dbProvider.getDB()
      .then((db: SQLiteObject) => {
        let sql = " INSERT INTO itens_venda ( id_venda "
                                        +" , key_venda "
                                        +" , nr_pedido "
                                        +" , id_tabela_preco "
                                        +" , id_produto "
                                        +" , nr_item "
                                        +" , qt_item "
                                        +" , vl_desconto "
                                        +" , pc_desconto "
                                        +" , vl_unit_item "
                                        +" , vl_total_item "
                                        +" , vendido "
                                        +" ) "
                +" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
        let data = [itemVenda.id_venda
        return db.executeSql(sql, data)
          .catch((e) => console.error(e));
      .catch((e) => console.error(e));

But this is a child table and when i close the modal i use this method calculaVenda() to calculate the father table with the data of the child table… but in this time when i close the modal the data seems not to have inserted yet on the sqlite database but if i open the modal an close just close don’t insert anything the method calculaVenda() return data of the database…

That’s because executing SQL is an asynchronous task.
This means that your app is still executing the SQL when closing the modal.

Look into promises and all will be clear.

MattE i will try today, afternoon i reply if work or not. Thank u so much for now…