如何清除ng-select选择 [英] How to clear ng-select selection
本文介绍了如何清除ng-select选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过编程方式清除ng-select下拉列表的选择?我想要单击清除图标的等效行为,但是是通过编程方式触发的.
Is it possible to programmatically clear the selection of an ng-select dropdown? I'm wanting the equivalent behaviour of clicking the clear icon, but triggered programmatically.
我期望使用clear()
方法或类似方法,但是文档化的API a>沿这些方向没有任何东西.
I was expecting a clear()
method or something similar, but the documented API doesn't have anything along those lines.
这是我的下拉代码:
<ng-select class="ng-select-wrap"
[searchFn]="multiTermSearch"
[items]="calculationOptions"
placeholder="Please select..."
name="calculation"
#calculationValue="ngModel"
[(ngModel)]="selectedCalculation">
</ng-select>
推荐答案
这是评论的解决方案:
// Access ng-select
@ViewChild(NgSelectComponent) ngSelectComponent: NgSelectComponent;
// Call to clear
this.ngSelectComponent.handleClearClick();
请注意,文档中并未将handleClearClick
公开为公共api方法,但是 Tim 提到它是公共方法,因此可以调用它.
Note that handleClearClick
isn't exposed in docs as public api method however as Tim mentioned it's public method so it's possible to call it.
这篇关于如何清除ng-select选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文