ionic 2 ion-select - 以编程方式关闭选择框 [英] ionic 2 ion-select - close select box programmatically
本文介绍了ionic 2 ion-select - 以编程方式关闭选择框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从事 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
函数中.
put this inside your closeAndSave
function.
在此之前,您需要从 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();
}
}
这篇关于ionic 2 ion-select - 以编程方式关闭选择框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文