ng-repeat filter on boolean

前端 未结 5 1817
再見小時候
再見小時候 2021-02-02 05:16

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

List of unregistered users:

    

Unregistered Users

5条回答
  •  既然无缘
    2021-02-02 06:03

    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.

提交回复
热议问题