Reverse polarity of an angular.js filter

前端 未结 4 816
离开以前
离开以前 2020-12-05 22:56

Given a filter method that returns true if some condition is met, is it possible to invoke its opposite in HTML, e.g. to use:

\"item in items | filter:!AllDa         


        
4条回答
  •  臣服心动
    2020-12-05 23:54

    shacker's answer didn't work for angular 1.0.7, so here's another way to do this:

    // You can register this in your AppCtrl if you like, otherwise just use $scope.
    $rootScope.not = function(func) {
        return function (item) { 
            return !func(item); 
        }
    };
    

    Then you would do this:

    filter:not(myFilterMethod)
    

提交回复
热议问题