离子2离子选择 - 以编程方式关闭选择框 [英] ionic 2 ion-select - close select box programmatically
本文介绍了离子2离子选择 - 以编程方式关闭选择框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究ionic2项目。
我使用离子选择元素。
I'm working on ionic2 project. I use ion-select element.
我搜索了一种方法,以编程方式关闭选择框选择任何项目(不等待用户按OK) )。
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?*/
}
`
推荐答案
这就是我所做的:
this.court = val;
this.select.close();
将其放入 closeAndSave
函数中。
在此之前你需要从closeAndSave函数传递一些值,如:
Before that u need to pass some value from your closeAndSave function like:
(ionSelect)="closeAndSave('someValueHere')"
然后在你在那里使用该值TS代码:
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离子选择 - 以编程方式关闭选择框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文