How to set default value for PrimeNG p-dropdown

后端 未结 8 1124
南笙
南笙 2020-12-09 17:53

I am using PrimeNG in my angular5 app. I have issue with p-dropdown

Question

I have p-dropdown for showing countries. I bind the select opti

8条回答
  •  猫巷女王i
    2020-12-09 18:46

    This may be caused if PrimeNG doesn't know to which field to bind the "selectedCountry", ie. your "countries" model for the dropdown control has more then key and value properties.

    In my case, I had to explicitly "tell" to each dropdown field that the property for values is "value". I used the p-dropdown dataKey property for this.

    So, in my dropdown control, I added something like this:

    
    

    You can read more here.

提交回复
热议问题