4

I'm working on ionic2 project. I use ion-select element.

I search after a way to close the select-box programmatically on select any item (not wait the user to press OK).

  <ion-select id="select" #select>
      <ion-option (ionSelect)="closeAndSave()" *ngFor="let option of enumList" [value]="option">{{ option}}</ion-option>
    </ion-select>

`

class myClass{
    @viewChild('select') select:Select;
    closeAndSave(){
        /*it is come here on press any option. but how can I close here my select element? I tried: this.select.destroy()  - not do any thing. any solution?*/
    }

`

1
  • please give solution , how you solved it Jun 22, 2017 at 7:05

4 Answers 4

7

this is what I did:

this.court = val;
this.select.close();

put this inside your closeAndSave function.

Before that u need to pass some value from your closeAndSave function like:

(ionSelect)="closeAndSave('someValueHere')"

then use this value there in you TS code:

import { Select } from 'ionic-angular';

class myClass{
    @ViewChild(select) select:Select;
    closeAndSave(val){
    this.someVar = val;
        this.select.close();
    }
}
2
1

try to test this tag:

you only need to add interface="action-sheet" in the ion-select element.

  <ion-item>
    <ion-label>Gender</ion-label>
    <ion-select interface="action-sheet">
      <ion-option value="f" selected="true">Female</ion-option>
      <ion-option value="m">Male</ion-option>
    </ion-select>
  </ion-item>

I'm not sure if that's a valid option (in terms of UX) in your app.

source : https://stackoverflow.com/a/39015858/308578

1
  • 1
    By far the most accurate answer.
    – Vova
    Nov 15, 2019 at 11:01
1

I used this: (document.querySelector('ion-backdrop') as HTMLElement).click();

-1

I'm not sure if this works, but it is shown as a popup and popups can be dismissed with the ionic ViewController.

You can use it like this:

import { ViewController } from 'ionic-angular'
...
export class YourComponent {
    constructor(private viewCtrl: ViewController){}
    closeAndSave(){
        //save things here 
        this.viewCtrl.dismiss();
    }
}
1
  • 1
    Thank you but not work... it dismiss the last page that push to the stack. Dec 21, 2016 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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