Angular ng-repeat filter on subarray

后端 未结 2 890
闹比i
闹比i 2021-01-24 07:51

Using Angular, I\'m trying to filter using ng-repeat on FactorName given the following schema.
Filtering using <... ng-model=\"query.Factors.FactorName\" ...> doesn\'t wo

2条回答
  •  礼貌的吻别
    2021-01-24 08:20

    There is also another place where you can iterate on a array, working along side ng-repeat, in the double bindings with a custom filter.

    Working Demo

    HTML

    • {{ x.Factors | factorFilter }}

    JS

    app.filter('factorFilter', function() {
        return function(items) {
            var results = [];
            if (items) {
                for (var i = 0; i < items.length; i++) {
                    results = items[i]['FactorName'];
                }
                return results;
            } else {
              return 'Doh!';
            }
       }
    })    
    

提交回复
热议问题