1

I have a results page. When navigating to this page, a search modal is created directly.

In the search page user can introduce a query and submit his search, or cancel.

In case there is a query, the results page is showing the results.
On the other hand, if user cancel the search, I want to pop the result page:

openSearchModal() {
  let searchModal = this.modalCtrl.create(SearchPage, {
       :
       :
  });
  SearchModal.onDidDismiss(data => {
    this.handleModalData(data);
  });
  searchModal.present();
}


handleModalData(data) {
  let q = data['q'];

  if (!q) {
    this.navCtrl.pop();                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
  } else {
    // handle search query......
           :
           :
  }
}

My problem is that when canceling the search, user gets to see for a second the results page before app sends him back.

I tried to use popTo from modal, but couldn't manage to achieve what I want.

1 Answer 1

1

You should handle the pop in the modal onDidDismiss()

presentModal() {
   this.searchModal = this.modalCtrl.create(SearchPage, { //stuff });
   this.searchModal.onDidDismiss(data => {
        this.navCtrl.pop();
    });
    this.searchModal.present();
}

Then

handleModalData(data) {
   let q = data['q'];

   if (!q) {
     this.searchModal.dismiss();                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
   } else {
    // handle search query
 }
1
  • The thing is the login is - I dismiss modal anyway. Only if modal did not return any data, I do pop. So both functions are part of the page which launches the modal....
    – guyaloni
    Commented Apr 6, 2017 at 9:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.