AngularJS: 如何有条件地应用两个过滤器?

AngularJS: How to apply two filters conditionally?

我有两个过滤器 (buildFilter:searchText && filter:searchText),我想在 searchText.APP.VERSION is true 应用时有条件地应用它们 buildFilter:searchText 否则 filter:searchText 我正在尝试使用三元运算符但它不起作用,不确定实现此目的的不同方法是什么。

<tbody ng-repeat="result in filtered = (vm.ProcessedResults | searchText.APP.VERSION ? buildFilter:searchText : filter:searchText) track by result.ENV_ID">

有点坚持这一点,任何帮助都会有所帮助。谢谢

试试这个

<tbody ng-repeat="result in filtered | filter: (!searchText.APP.VERSION ? searchText:'') | buildFilter:(searchText.APP.VERSION ? searchText:'') track by result.ENV_ID">

这是根据条件使用多个过滤器的示例

<div ng-controller="MainCtrl">
    <ul>
        <li ng-repeat="mentor in mentors | filter:(search ? searchText:filterFn )">{{mentor}}</li>
    </ul>
</div>

脚本

var app = angular.module('myApp', []);

function MainCtrl( $scope ) {
    $scope.mentors = [ 'Jonathan', 'Nathan', 'Chris', 'Brian', 'Timothy' ];
    $scope.searchText = "j";
  $scope.search = false;

$scope.filterFn = function(car)
{
    // Do some tests

    if(car == 'Nathan')
    {
        return true; // this will be listed in the results
    }

    return false; // otherwise it won't be within the results
    };

}

https://jsfiddle.net/9gp3w7vx/