【问题标题】:Clear value and dropdown of ng-select after select the value选择值后清除 ng-select 的值和下拉列表
【发布时间】:2019-07-29 13:14:59
【问题描述】:

我正在处理一个包含ng-select 下拉列表的angular 8 项目。它是typehead 和ng-select 的组合。这样我就可以实时从api中获取数据。下拉菜单工作正常。但我找不到功能。

我需要进行选择,并且在我进行选择后,预填充的下拉列表会被清除。

我可以清除选择。但是我不知道如何清除已经填充了以前的搜索数据的下拉列表。

我正在使用this.selectedCustomer = null; 清除选择。

我尝试了question 中给出的答案,它也给出了相同的结果。

我试过了

@ViewChild(
'customerSearch', {
  static: true,
  read: NgSelectComponent
}
) customerSearch: NgSelectComponent;

和

this.customerSearch.handleClearClick();

这与this.selectedCustomer = null的目的相同

我的html是

<form [formGroup]="heroForm">
<ng-select
[items]="customers | async"
bindLabel="name"
[addTag]="addNewPersonRef"
addTagText="Add new person"
[hideSelected]="false"
[trackByFn]="trackByFn"
[loading]="customerLoading"
[typeahead]="searchInput"
[(ngModel)]="selectedCustomer"
[ngModelOptions]="{standalone: true}"
(ngModelChange)="openCustomerWindow($event)">
<ng-template ng-option-tmp let-item="item" let-search="searchTerm">
  <div [ngOptionHighlight]="search">{{item.name}}</div>
  <small><i class="fas fa-folder" title="File No"></i> {{item.fileId}} &nbsp;&nbsp; <i class="fas fa-id-card" title="Qatar ID"></i> {{item.qid}}</small>
</ng-template>
</ng-select>
</form>

是否有任何选项可以以编程方式清除已填充的下拉列表?任何帮助都将不胜感激。谢谢。

【问题讨论】:

  • 你试过清除customers吗?

标签: angular angular8 angular-ngselect


【解决方案1】:

在您的 HTML 中:

[items]="customers | async"

这是不同选项所在的位置,清空它应该会清除下拉菜单。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 2023-02-09
    相关资源
    最近更新 更多