字母排序下拉
问题描述:
我刚开始使用Angular 2和TypeScript。我很难为它实现代码。 我的问题是如何在我的下拉列表中做排序选项?字母排序下拉
下面是HTML代码:
<div class="col-12">
<select class="form-control" id="type" [(ngModel)]="measure" (change)="getMeasures()">
<option *ngFor="let option of options" [ngValue]="option.measure">{{option.display}}</option>
</select>
</div>
这里是我的打字稿供选的部分:
options = [
{
measure: 'length',
display: 'Length'
},
{
measure: 'area',
display: 'Area'
},
{
measure: 'volume',
display: 'volume'
},
{
measure: 'time',
display: 'Time'
},
{
measure: 'current',
display: 'Current'
},
{
measure: 'energy',
display: 'Energy'
},
]
答
您可以使用angular2的管道,说orderBy
,
<div class="col-12">
<select class="form-control" id="type" [(ngModel)]="measure" (change)="getMeasures()">
<option *ngFor="let option of options | orderBy : 'measure'" [ngValue]="option.measure">{{option.display}}</option>
</select>
</div>
+0
downvote?以什么方式 – Sajeetharan
答
排序管施加看到https://angular.io/guide/pipes
<option *ngFor="let option of options | orderBy:'measure'" [ngValue]="option.measure">{{option.display}}</option>
澄清你的问题,你所面临的问题。你想排序哪个度量? – Abrar
@Abrar当我点击下拉菜单时,我想对它们进行排序,以便它们在我的列表中以aphabetical顺序排列。所以首先将区域当前等。 – pooh098
@ pooh098你检查我的鼻子 – Sajeetharan