ng-repeat filter on boolean

Problem

I am trying to filter on a boolean value in an ng-repeat.

List of unregistered users:

    <h3>Unregistered Users</h3>
    <div ng-repeat="user in users | filter:!user.registered">
        <div class="row-fluid">
        <div class="span2">
          {{user.name}}
        </div>
      </div>
    </div>

List of registered users:

    <h3>Registered Users</h3>
    <div ng-repeat="user in users | filter:user.registered">
        <div class="row-fluid">
        <div class="span2">
          {{user.name}}
        </div>
      </div>
    </div>

Is there a good way to filter based on registered and !registered.

Problem courtesy of: lostintranslation

Solution

filter by obj expression:

<h3>Unregistered Users</h3>
<div ng-repeat="user in users | filter:{registered:false}">
    <div class="row-fluid">
    <div class="span2">
      {{user.name}}
    </div>
  </div>
</div>

JSFiddle: http://jsfiddle.net/alfrescian/9ytDN/

Solution courtesy of: alfrescian

Discussion

Slight modification to Websirnik's answer, this allows any column name for the dataset:

.filter('onlyBooleanValueFilter', [function () {
    return function (input, column, trueOrFalse) {
        var ret = [];

        if (!angular.isDefined(trueOrFalse)) {
            trueOrFalse = false;
        }

        angular.forEach(input, function (v) {
            if (angular.isDefined(v[column]) && v[column] === trueOrFalse) {
                ret.push(v);
            }
        });

        return ret;
    };
}])

Markup:

<div repeat="row in your.dataset | onlyBooleanValueFilter: 'yourColumn' : true"> 
     ...your stuff here....
</div>
Discussion courtesy of: Shawn Dotey

Had the same question. Alfrescian solution didn't work for me on Angular 1.1.5.

Found this fiddle: http://jsfiddle.net/buehler/HCjrQ/

.filter('onlyBooleanValueFilter', [function(){
    return function(input, param){
        var ret = [];
        if(!angular.isDefined(param)) param = true;
        angular.forEach(input, function(v){
            // 'active' is a hard-coded field name
            if(angular.isDefined(v.active) && v.active === param){
                ret.push(v);
            }
        });
        return ret;
    };
}])

You would need to adjust the code of the filter according to your field.

Discussion courtesy of: Websirnik

Create a method in the controller which returns true or false based on the logic you need and specify that function in the filter.

Something like this:

$scope.isRegistered = function(item) {
  return item.registered;
};

<h3>Unregistered Users</h3>
<div ng-repeat="user in users | filter:!isRegistered ">
    <div class="row-fluid">
    <div class="span2">
      {{user.name}}
    </div>
  </div>
</div>
Discussion courtesy of: Giorgi

This recipe can be found in it's original form on Stack Over Flow.