2

I have this filter modal in which i can choose a country to show. Now, when i already have a selected country then i open the modal and close it without making a new selection, i still want that specific previously selected country to show only. Right now, all the items are displayed in this case. How can i fix this?

modal.ts

closeModal(data) {
    this.viewCtrl.dismiss(data?data:null);
  }

country.ts

myModal.onDidDismiss(data => {

          let selectedCountry = data;
          console.log(selectedCountry)
          if(selectedCountry === null || selectedCountry === 'all'){
            return this.modifiedItems = this.items
          }

          else {
            this.modifiedItems = this.items.filter((data) => {
              return data.location === selectedCountry
            })
          }
        });

        myModal.present();
Ichraf
  • 345
  • 1
  • 7
  • What does the console log show after selecting a country? And u r using the variable name data twice within a similar scope which may be ambiguous hence creating issues – TomG Apr 01 '18 at 14:19
  • @TomG. After selecting a specific country, the onDismiss is called. AND if i dont select a specific country and just close the modal, the onDismiss is also called. So that is why this happens. –  Apr 01 '18 at 14:38

1 Answers1

0

When nothing is selected, does your data equals null or all the countries? Anyhow, I think you should dismiss your modal with null when nothing is selected. Then, in your onDidDismiss check if data is not null before doing the rest. You may also need to make selectedCountry global.

adiga
  • 34,372
  • 9
  • 61
  • 83
Ichraf
  • 345
  • 1
  • 7