ng-option 过滤器不工作 angularjs

ng-option filter not working angularjs

我正在尝试使用 ng-options 在 select 中显示数组中的数据,我想过滤它,但它不起作用。我不想显示具有 billHeadShortForm=FEC & FDG

的对象

这是我的HTML

<select class="form-control" ng-init="getBillHeadCurrentProjWise()" ng-model="headID" ng-options="h.billHeadID as h.billHead for h in billHeadsProjWise | filter:h.billHeadShortForm!='FEC' | h.billHeadShortForm!='FDG'">
     <option value="">--Select Billing Head--</option>
</select>

ng-options 的过滤器部分调整为以下内容:

ng-options="... | filter: {billHeadShortForm: '!FEC'} | filter: {billHeadShortForm: '!FDG'}"

fiddle

尽管如此,您可能想要阅读 filter documentation,并编写一个函数来避免管道连接两个过滤器。

编辑:

函数可能是这样的:

$scope.filterBillHead = function (billHead) {
    // Exclude 'FEC' and 'FDG'
    // return true if billHeadShortForm is not in the array, false otherwise
    return ['FEC', 'FDG'].indexOf(billHead.billHeadShortForm) < 0;
}

模板:

ng-options="... | filter: filterBillHead"

updated fiddle

我找到了解决方案

  $scope.myFunction = function (Billhead) {
    if (Billhead.billHeadShortForm == 'FEC' || Billhead.billHeadShortForm == 'FDG' || Billhead.billHeadShortForm == 'GL') {
        return false;
    } else {
        return true;
    }
}


  ng-options="h.billHeadID as h.billHead for h in billHeadsProjWise | filter:myFunction"