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

Published

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>

Source: Angular Questions

Published
Categorized as angular, primeng, primeng-dropdowns Tagged , ,

Answers

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq