I am using p-dropdown
in my app and have noticed that after upgrading to PrimeNG 9 & Angular 10, the p-dropdown
is no longer taking the custom value as the default value. Instead it takes the first value present in the options list as the default value. Further more the label now only fills half of the drop down while the reset is just empty. How can I fix this? Thanks in advance.
here is my template:
<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>
here is my ts code:
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' };
Dropdown selects the first option to be the default value, if you don't want this behaviour, you have to go with the placeholder, then the default value will not be the first option.
Also if you want to get just the value from the selected object you need to specify the optionValue parameter in the p-dropdown
code:
Now here you may specify a different value as the answer(a value that does not exist in the options, that value will remain the value as long as its changed), which you can set as the default value
Checkout this demo Demo