使用具有多个过滤器的别名

时间:2017-05-17 08:07:34

标签: javascript angularjs angularjs-filter angularjs-limitto

我有这段代码:

<tr ng-repeat="person in ctrl.persons
            | filter : { name: filterName, email: filterEmail} as filtered">

Number of persons filtered by mail and name: {{filtered.length}}

现在我添加另一个过滤器:

<tr ng-repeat="person in ctrl.persons
                    | filter : { name: filterName, email: filterEmail} 
                    | limitTo : ctrl.size as filtered">

Number of persons filtered by mail and name: {{filtered.length}}

我的问题是,通过邮件和姓名过滤的人数现在是错误的,因为它仅限于size。解决这个问题的最佳解决方法是什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

我用括号解决了这个问题:

<tr ng-repeat="person in filteredPersons = (ctrl.persons
                        | filter : { name: filterName, email: filterEmail})
                        | limitTo : ctrl.size as filtered">

Number of persons filtered by mail and name: {{filteredPersons.length}}