1
<tbody>
        <tr ng-repeat="y in Summary">
            <td>{{y.ID}}</td>                       
            <td>{{y.submitTime}}</td>
            <td>{{y.timeTaken}}</td>
            <td>{{y.description}}</td>
        </tr>
</tbody>

I want to filter the values when user selects a checkbox-exclude Non-members.

So the Non member array has IDs of users.

$scope.Nonmember=["521","234","456", etc]

So when the user selects the checkbox I want to remove the rows which have IDs in nonmember . Can a filter be used for searching through the whole array ?.. or ng-show/hide/if can be used??

2
  • I suggest that you identify which records are members in advance that way your filter just needs to work on your checkbox = true and member =true Commented Aug 10, 2016 at 6:55
  • there's the problem, the nonmember array is dynamic , the values are retrieved from ajax calls. Commented Aug 10, 2016 at 6:57

1 Answer 1

3

A filter can do.

For example:

angular
    .module( ... )
    .filter( 'excludeNonMembers', function(){
        return filterMembers;
    } );

function filterMembers( summary, nm, exclude ){
    if(!exclude) return summary;
    if( !nm || nm.length == 0 ) return summary;
    return summary.filter( function( i ){
        return nm.indexOf( i.ID ) == -1;
    } );
}

In your html:

 <tr ng-repeat="y in summary | filter:excludeNonMembers:Nonmember:exclude"> 

The $scope.exclude variable is a boolean that you toggle somewhere to apply the filter.

Sign up to request clarification or add additional context in comments.

1 Comment

This look like exactly what i needed !

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.