Cannot close modal


#1

I created a simple shopping list app. The last thing that i implemented was a function to calculate the total but after this i cannot close the modal because the error message says: Cannot read property ‘price’ of undefined.

this is the repository i put the code: https://github.com/webofbits/shopping-list


#2

In onDismiss() handler in update() method (in home.js) you don’t check if the product is returned (and in the case when using the exit() method in the modal it’s not), add the following check and it should fix the problem:

  // home.js
  update(product) {
    let modal = Modal.create(ModalCartPage, {params: product});
    modal.onDismiss((product) => {
      // NOTE: Perform these operations only when a product is returned.
      if (product) {
        // update product
        this.dao.update(product);
        // re-calculate total:
        this.totalPrice = this.dao.totalPrice();
      }
    })
    this.nav.present(modal);
  }

#3

worked! But in the create method. So i put the conditional in update and create. Thanks for the hint!