gpt4 book ai didi

ionic2 - ionic 2 ion-select - 以编程方式关闭选择框

转载 作者:行者123 更新时间:2023-12-01 09:49:25 26 4
gpt4 key购买 nike

我正在研究 ionic2 项目。
我使用 ionic 选择元件。

我搜索了一种在选择任何项目时以编程方式关闭选择框的方法(不等待用户按 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 函数传递一些值,例如:
(ionSelect)="closeAndSave('someValueHere')"

然后在你的 TS 代码中使用这个值:
import { Select } from 'ionic-angular';

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

关于ionic2 - ionic 2 ion-select - 以编程方式关闭选择框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41237061/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com