satyender
satyender

Reputation: 837

ng-option filter not working angularjs

I'm trying display data from an array in a select using ng-options and I want filter it which is not working. I don't want to show object having billHeadShortForm=FEC & FDG

Here is my 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>

Upvotes: 0

Views: 698

Answers (2)

Michel
Michel

Reputation: 28299

Adjust the filter part of the ng-options to the following:

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

See fiddle

Although, you might want to read filter documentation, and write a function to avoid piping two filters.

Edit:

The function could be something like that:

$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;
}

Template:

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

See updated fiddle

Upvotes: 0

satyender
satyender

Reputation: 837

I have found solution

  $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"

Upvotes: 1

Related Questions