Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PrimeNg p-dropdown Does not Display Array Values

I have component using PrimeNg p-dropdown.
html code:

<p-dropdown [style]="{'width':'150px'}" [options]="portNames" placeholder="Select a Port">
</p-dropdown>

ts portNames decleration:

portNames: string[] =["Port 01","Port 02", "Port 03"];

My Problem is that DropDown Does not Display Values "Port 01","Port 02", "Port 03".

Maybe I have any mistake?

like image 882
Rachel Fishbein Avatar asked Mar 20 '18 07:03

Rachel Fishbein


Video Answer


2 Answers

Try adding your dropdown values in label and values

portNames =[
{label:'Port 01', value:'Port 01'},
{label:'Port 02', value:'Port 02'},
{label:'Port 03', value:'Port 03'},
];
like image 112
Mancy Saxena Avatar answered Oct 23 '22 07:10

Mancy Saxena


portNames should be an array of objects composed of a label and a value (not an array of strings) :

portNames = [
        {label:'Port 01', value:'p01'},
        {label:'Port 02', value:'p02'},
        {label:'Port 03', value:'p03'}
        ];

See Plunker

like image 25
Antikhippe Avatar answered Oct 23 '22 08:10

Antikhippe