如何预先选择 Primeeng 下拉值? [英] How to pre select Primeng Dropdown values?
本文介绍了如何预先选择 Primeeng 下拉值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 angular 应用中有包含一组值的 Primeng 下拉菜单.
I have primeng dropdown with set of values in my angular app.
在视图 Screen 中,下拉不显示所选值(保存在 db 中的值),而是显示选择".
In the view Screen , drop down is not displaying the selected value (value saved in db) instead it displays 'Select'.
HTML:
<p-dropdown [options]="reasons" [(ngModel)]="selectedReason" (onChange)="getCompleteReason($event)" styleClass="ui-column-filter" filter="true"> </p-dropdown>
组件.ts
this.reasons = [];
this.reasons.push({label: 'Select', value: null});
this.reasons.push({label: 'Reason 1', value: 'Reason 1'});
this.reasons.push({label: 'Reason 2', value: 'Reason 2'});
this.reasons.push({label: 'Reason 3', value: 'Reason 3'});
this.reasons.push({label: 'Other', value: 'Other'});
this.selectedReason = 'Reason 2' (eg value stored in the db)
推荐答案
在我将 name 属性添加到下拉列表后它起作用了
It worked after i added name attribute to the dropdown
<p-dropdown [options]="reasons" [(ngModel)]="selectedReason" name="selectedReason" (onChange)="getCompleteReason($event)" styleClass="ui-column-filter" filter="true">
这篇关于如何预先选择 Primeeng 下拉值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文