The p-dropdown below is reading json data from API. Among the data values, I want to set up "apple" by default. Currently, in the p-dropdown, the first thing users can see is the placeholder value (i.e "Select a Product").
How can I preset a default value in p-dropdown? Any help or advice, please?
<p-dropdown
[options]="products"
optionLabel="productName"
optionValue="productId"
placeholder="Select a Product"
[filter]="true"
filterBy="productName"
></p-dropdown>
[
{
productName: "apple",
productId: 1
},
{
productName: "banana",
productId: 2
},
{
productName: "watermelon",
productId: 3
},
]
You can use an
ngModelto tie your currentselectedItemto thedropdownselected item and viceversa.It's important that you do add that property to your Angular component, in order to be able to use it.
Edit: Here's an example for your component:
Let me know if that helped!