加载下拉值字母顺序角度 6 [英] load drop down values alphabetic order angular 6
本文介绍了加载下拉值字母顺序角度 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试按字母顺序加载下拉列表.目前我在下拉菜单中使用了唯一值管道.我如何添加另一个管道以获得字母顺序..
I am trying to load drop down with alphabetic order. currently i used unique value pipe for the drop down. how i add another pipe for get alphabetic order..
<select class="form-control fix-dropdown" required
(change)="batchSorceList();"
[ngClass]="{'is-invalid':glheaderform.submitted && orgname.invalid}"
#orgname="ngModel" [(ngModel)]="orgNameModel.orgName"
name="orgName">
<option value="undefined" disabled="true">--Select--</option>
<option *ngFor="let bank of orgNameModel | unique ">{{bank.orgName}}</option>
</select>
推荐答案
作为 Angular 的最佳实践,你不应该使用 OrderPipe
As a best practice in Angular, you should not use OrderPipe
如果您想根据名称对项目进行排序,请使用纯javascript排序功能,如下所示
if you want to sort items based on names, use the pure javascript sort function as follows
sortBy(prop: string) {
return this.orgNameModel.sort((a, b) => a[prop] > b[prop] ? 1 : a[prop] === b[prop] ? 0 : -1);
}
在你的 HTML 中,
and in your HTML,
<option *ngFor="let bank of of filterBy('orgName')"| unique ">{{bank.orgName}}</option>
这篇关于加载下拉值字母顺序角度 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文