Dropdown placeholder not redndered

UI Components for Angular
Post Reply
jss88
Posts: 3
Joined: 07 Feb 2017, 09:22

13 Mar 2017, 11:04

Hi, dropdown placeholder not rendered. I tried to switch to newest release 2.0.3, but the problem still exists, here is code:

<p-dropdown [options]="cities" [(ngModel)]="selectedCity" placeholder="Select a City" [style]="{'width' : '100%'}"></p-dropdown>

cities: SelectItem[];
selectedCity: string;

constructor() {
this.cities = [];
this.cities.push({ label: 'New York', value: { id: 1, name: 'New York', code: 'NY' } });
this.cities.push({ label: 'Rome', value: { id: 2, name: 'Rome', code: 'RM' } });
this.cities.push({ label: 'London', value: { id: 3, name: 'London', code: 'LDN' } });
this.cities.push({ label: 'Istanbul', value: { id: 4, name: 'Istanbul', code: 'IST' } });
this.cities.push({ label: 'Paris', value: { id: 5, name: 'Paris', code: 'PRS' } });
}

And in dropdown 1 element is NewYork, but selectedCity was never define in the code

jss88
Posts: 3
Joined: 07 Feb 2017, 09:22

13 Mar 2017, 11:39

By the way I found on github in sources of showcase :
this.cities.push(&#123;label:'Select City', value:null&#125;);

so placeholder option must be hardcoded in the model to work properly?

pankajpawar
Posts: 1
Joined: 23 Feb 2021, 10:12

23 Feb 2021, 10:14

Add optionValue attribute along with optionLabel to p-dropdown. Then it works.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: trevor.rodgers and 5 guests