Angularjs filter negated

后端 未结 6 709
迷失自我
迷失自我 2020-11-30 10:01

I have a set of items that I want to filter in ng-repeat using an ng-model as the string to filter the set, so far I haven\'t found a way to make it work when the expression

6条回答
  •  难免孤独
    2020-11-30 10:22

    If you're using a method to filter than prefixing the method name with '!' will not work. Instead you can do something like:

    // 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 do:

    filter:not(myFilterMethod)
    

    In your html it would look like:

    
    

    Reference: https://stackoverflow.com/a/17811582/175830

提交回复
热议问题