How to pass multiple parameter in angular filter function, not custom filter

前端 未结 4 2153
傲寒
傲寒 2021-02-20 14:45

I tried hard and visit lot of similar question like this but still unable to solve this issue.

I want to pass extra parameter in angular filter function. I found solutio

相关标签:
4条回答
  • 2021-02-20 14:59

    Will try:

    $scope.isStatus = function(secondParam, thirdParam){
          return function(user) {
               console.log(secondParam);
               console.log(thirdParam);
               return user.status == $scope.status;
         }
    

    Updated version http://jsfiddle.net/4PYZa/282/

    0 讨论(0)
  • 2021-02-20 15:01

    According to your case, you can use predicate expression instead of custom filter:

    <li ng-repeat="user in users | filter:{status: status, name: name}">{{user.name}}</li>
    

    Take a look at this fiddle: http://jsfiddle.net/ovym2tpr/28/

    You can use custom filter in anyway, it just performs not very well especially under nested ng-repeat

    0 讨论(0)
  • 2021-02-20 15:06

    How do I call an Angular.js filter with multiple arguments?

    AngularJS : Custom filters and ng-repeat

     myApp.filter("isStatus ", function() { // register new filter
         return function(user, secondParam, thirdParam) { // filter arguments
    
           return user.status == $scope.status; // implementation
        };
     });
    

    Calling from Template

    <li ng-repeat="user in users | isStatus:secondParam">{{user.name}}</li>
    
    0 讨论(0)
  • 2021-02-20 15:19

    It's very simple , just do this

    <li ng-repeat="user in users | filter:user | filter : secondParam)">{{user.name}}</li>
    
    0 讨论(0)
提交回复
热议问题