0

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>

2 Answers 2

1

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"
Sign up to request clarification or add additional context in comments.

1 Comment

this is by far the best solution to this problem, to further this you could create a new angular filter that wraps the existing one with your business logic in. That way you can remove this logic from the controller and into something more apt.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.