angular ng-repeat with condition

前端 未结 4 1914
猫巷女王i
猫巷女王i 2020-12-09 12:07

How do you do something like this in angular with ng-repeat? I\'ll be using the example from the documentation which inits an array with 2 friends, what if I wanted to only

4条回答
  •  鱼传尺愫
    2020-12-09 12:30

    Create a custom filter.

    HTML:

    
    

    and

  • JS:

    var someApp=angular.module('someApp', []);
    
    someApp.filter('age', function() {
        return function(input, uppercase) {
            var out = [];
            for (var i = 0; i < input.length; i++) {
                if(input[i].age >= 26){
                    out.push(input[i]);
                }
            }
            return out;
        }
    });
    

提交回复
热议问题