Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic 2 ion-select - close select box programmatically

Tags:

ionic2

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?*/
    }

`

like image 359
user5260143 Avatar asked Feb 05 '23 12:02

user5260143


1 Answers

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();
    }
}
like image 62
yash_DedSec Avatar answered Mar 16 '23 10:03

yash_DedSec