如果串列為空,我需要隱藏 ng-select 的選項串列。現在,如果我單擊選擇框,或者搜索結果為空,則會No items found顯示具有此值的選項串列。我不需要這個功能。相反,我需要隱藏選項串列。
<ng-select placeholder="PLZ / Ort" [searchable]="true" [searchFn]="customSearch" (search)="searchLocation($event.term)" (clear)="clearLocationList()" (change)="setLocation($event)" formControlName="location" required>
<ng-option *ngIf="isLocationLoading else noLoader" [disabled]="true"><i ></i> Loading...</ng-option>
<ng-template #noLoader>
<div *ngFor="let locations of locationList">
<ng-option *ngFor="let location of locations" [value]="location">{{location?.zip}} {{location?.place}}
</ng-option>
</div>
</ng-template>
</ng-select>

uj5u.com熱心網友回復:
您可以使用標簽[isOpen]內的屬性<ng-select>來實作您的目標,如下所示:
[isOpen] = "!locationList.length? false : null"
如果其中沒有專案,這將阻止打開下拉串列。
另一種選擇是使用適合您的應用程式的內容更改顯示文本本身,甚至使用notFoundText內部的屬性將其設定為空字串<ng-select>
uj5u.com熱心網友回復:
將其包裝成一個 div 并使用 ngIf 隱藏它以防串列沒有專案
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/416712.html
標籤:
下一篇:模態彈出的角度單元測驗
