Reputation: 31
I would like to static add options for p-dropdown.
<p-dropdown [(ngModel)]="selectedOption"
placeholder="Select options" optionLabel="name"
(onChange)="onChangeOption()">
<option *ngFor="let item of items;" [value]="item.value">{{item.label}}</option>
<option value="null">Others</option>
</p-dropdown>
I have tried to dynamic add the "Others" option at ts file, but I still want to static add like this Is there any better way to do this ? Tks you all
Upvotes: 2
Views: 715
Reputation: 799
You cant use option directly in p-dropdown. You have to provide data to options array. For example here variable cities
hold the option arrays
<div class="card flex justify-content-center">
<p-dropdown
[options]="cities"
[(ngModel)]="selectedCity"
optionLabel="name"
placeholder="Select a City" />
</div>
if you don't want to provide it from controller class then you can directly pass the array in HTML itself like this
<div class="card flex justify-content-center">
<p-dropdown
[options]="[{name: 'Australia', code: 'AU'},{name: 'Brazil', code: 'BR'}]"
[(ngModel)]="selectedCity"
optionLabel="name"
placeholder="Select a City" />
</div>
Upvotes: 1