Stefan
Stefan

Reputation: 585

How filter in a view

i have this Code in my view

<div ng-repeat="config in configs">
     <div ng-repeat="test in tests ">
          <a href="#"> {{test[config.Name]}}</a></li>
     </div>
</div>

it works fine. But how can I filter test?

<div ng-repeat="test in Tests | filter:{[config.Name]:'Test'} ">

dont work. How can I filter the column config.Name?

Thanks for your Help

Stefan

Upvotes: 2

Views: 30

Answers (3)

Reactgular
Reactgular

Reputation: 54741

That's a tricky one, but if you put the filter value in a variable first that might work?

<div ng-repeat="config in configs" ng-init="$filter = {}; $filter[config.Name] = 'Test'}">
     <div ng-repeat="test in tests | filter : $filter">
          <a href="#"> {{test[config.Name]}}</a></li>
     </div>
</div>

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 691635

Add that function to your controller:

$scope.createFilter = function(property, value) {
    var result = {};
    result[property] = value;
    return result;
};

and use it in the view:

<div ng-repeat="test in Tests | filter: createFilter(config.Name, 'Test')">

Upvotes: 2

Nicolas2bert
Nicolas2bert

Reputation: 1152

Try this, I hope that could help you:

JS :

$scope.conf = [];
$scope.conf.Name = 'Test';

HTML:

<div ng-repeat="config in configs | filter:conf:strict">
     <div ng-repeat="test in tests ">
          <a href="#"> {{test[config.Name]}}</a></li>
     </div>
</div>

Upvotes: 0

Related Questions