我的标记如下所示:
<li *ngFor="let user of usersList | orderBy : ['name']; let i = index;">
那么是否只有当某些 bool 值为真时才应用 orderBy 管道?
最佳答案
怎么样
<li *ngFor="let user of usersList | orderBy : [value ? 'name' : '']; let i = index;">
另一种选择是创建一个包装器管道,它接受一个参数并有条件地使用 orderBy 管道。
*编辑
正如@OliverRenner 所述,orderBy
在 2.0 中不再由 Angular 提供。以上假设您已经编写了自己的 orderBy
实现。
参见 https://angular.io/docs/ts/latest/guide/pipes.html#!#no-filter-pipe
关于Angular2 仅当特定值或 bool 值为真时才使用排序管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39175586/