[英]PrimeNG p-dropdown not taking custom default value
我在我的應用程序中使用p-dropdown
並注意到在升級到 PrimeNG 9 和 Angular 10 后, p-dropdown
不再將自定義值作為默認值。 相反,它將選項列表中的第一個值作為默認值。 此外,標簽現在只填充下拉列表的一半,而重置只是空的。 我怎樣才能解決這個問題? 提前致謝。
這是我的模板:
<div fxLayout="row" fxLayoutAlign="end center" fxLayoutGap="10px">
<p-dropdown [options]="cityList" tooltipPosition="left" [(ngModel)]="selectedCity" optionLabel="label"></p-dropdown>
<p-dropdown [options]="carList" tooltipPosition="left" [(ngModel)]="selectedCar" optionLabel="label"></p-dropdown>
</p-button>
</div>
這是我的 ts 代碼:
this.carList = [{ label: 'BMW', value: 'BMW' },{ label: 'Tesla', value: 'Tesla' },{ label: 'Toyota', value: 'Toyota' }];
this.cityList = [{ label: 'New York', value: 'New York' },{ label: 'Chicago', value: 'Chicago' },{ label: 'Boston', value: 'Boston' }];
this.selectedCity = { label: 'None', value: 'None' };
this.selectedCar = { label: 'None', value: 'None' };
為了讓下拉菜單將默認值設置為您的自定義值,您的值必須是列表的一部分。 因此,如果您想將其最初設置為“無”,則需要在列表中包含“無”。 請注意,您的selectedCity
和selectedCar
應僅設置為值,而不是 selectItems。 所以你應該只selectedCity = 'None'
等。
如果您不想將“無”添加到您的列表中,我建議您改用占位符 - 您可以在其中顯示placeholder
直到選擇了一個值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.