How to set value PrimeNG p-dropdown with a value read from the server?

Viewed 984

I receive the value of myModel.field correctly from a server (for example myModel.field = "id2"), but it is not selected in the p-dropdown, what should I do?

This is my options (the dropdown populates fine):

options = [
    { label: 'Opt1', value: 'id1' },
    { label: 'Opt2', value: 'id2' },
    { label: 'Opt3', value: 'id3' },
    { label: 'Opt4', value: 'id4' },
   ]

This is my dropdown in .html

<p-dropdown 
    [options]="options" [(ngModel)]="myModel.field" 
    optionLabel="label" optionValue="value" 
    [showClear]="true" [filter]="true" filterBy="label" 
    required="true">
</p-dropdown>
0 Answers
Related