AngularJS ng-repeat 多个过滤器之间的别名表达式

AngularJS ng-repeat alias expression between multiple filters

根据Angular ngRepeat documentation,您只能在ngRepeat的末尾使用别名表达式:

Please note that `as [variable name] is not an operator but rather a part of ngRepeat micro-syntax so it can be used only at the end (and not as operator, inside an expression).

在我的 ng-repeat 中,我需要根据 属性 过滤掉项目,然后使用 limitTo 过滤器进行分页。

如何在第二个过滤器之前获得过滤项目的数量?

这当然行不通:

item in c.items | filter: c.contextFilter as filteredItems | limitTo: c.pagination.pageSize : c.pagination.currentPage*c.pagination.pageSize

有没有其他方法可以获得 filteredItems.length 值?

我遇到了同样的问题,我修复了将过滤器表达式第一部分的结果分配给新变量的问题。在你的例子中:

    item in filteredItems = (c.items | filter: c.contextFilter) | limitTo: c.pagination.pageSize : c.pagination.currentPage*c.pagination.pageSize```

<div>{{filteredItems.length}}</div>

使用 controllerAs 语法的完整示例:

   item in $ctrl.filteredItems = ($ctrl.items | filter: $ctrl.customFilter | 
   orderBy: $ctrl.order) | limitTo: $ctrl.pagination.pageSize : 
   $ctrl.pagination.currentPage*$ctrl.pagination.pageSize`