我正在从事 ionic2 项目。
我使用离子选择元件。
我搜索一种在选择任何项目时以编程方式关闭选择框的方法(而不是等待用户按“确定”)。
<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 函数传递一些值,例如:
(ionSelect)="closeAndSave('someValueHere')"
然后在你的 TS 代码中使用这个值:
import { Select } from 'ionic-angular';
class myClass{
@ViewChild(select) select:Select;
closeAndSave(val){
this.someVar = val;
this.select.close();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)