Lam*_*Lac 1 label dropdown primeng angular
是否需要映射到标签和值才能在下拉列表中显示值?
我试图在下拉列表中显示枚举,但它们显示不正确!
export enum nature
{
annuelle="Annuelle",
semestrielle="Semestrielle",
trimestrielle="Trimestrielle"
}
Run Code Online (Sandbox Code Playgroud)
naturevalues = Object.values(nature);
Run Code Online (Sandbox Code Playgroud)
<div class="ui-grid-col-6">
<p-dropdown [options]="naturevalues" formControlName="nature"></p-dropdown>
</div>
Run Code Online (Sandbox Code Playgroud)
对于那些从 Google 来到这里的人:
nature.enum.ts
export enum Nature {
annuelle = "Annuelle",
semestrielle = "Semestrielle",
trimestrielle = "Trimestrielle"
}
Run Code Online (Sandbox Code Playgroud)
在component.ts 中:定义一个列表,其中Nature只是一个导入的枚举:
import {Nature} from 'enums/nature.enum';
//other imports
public natures = Nature;
Run Code Online (Sandbox Code Playgroud)
在您的模板中使用keyvalue管道并设置optionLabel为value:
<div class="ui-grid-col-6">
<p-dropdown [options]="natures | keyvalue" optionLabel="value" formControlName="nature"></p-dropdown>
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2973 次 |
| 最近记录: |