垫选择-垫选项排序值

时间:2018-08-21 19:51:40

标签: html angular typescript angular6

我是Angular6的新手,我想知道是否有一种简单的方法来做我想做的事。

我刚刚阅读了文档,却什么也没读,有没有一种简单的方法可以对下拉列表中的值进行排序?

<mat-form-field>
      <mat-select placeholder="Code List" required [(ngModel)]="contextScheme.codeListId">
        <mat-option *ngFor="let codeList of codeLists" [value]="codeList.codeListId">
            {{codeList.codeListName}}
        </mat-option>
      </mat-select>
</mat-form-field>

基本上,我的值是数据库中按ID排序的值,我想要确切的值,但按desc排序。

谢谢。

Sox-。

1 个答案:

答案 0 :(得分:1)

您应该在数据库后端进行排序,或者按照Angular团队在no order-by pipe中的建议进行排序,应该在组件内部进行排序。 例如。如果组件中有数组,则可以使用Array.sort

相关问题