Reputation: 555
i'm completely new to angular so forgive my question. I'm trying to create a list of filters with the user input. Here's a plunker of what i'm trying to do. http://plnkr.co/edit/asrZJj2HFJCnmmqJLlgt?p=preview
I understand that my condition for my ng-repeat should be something like that:
ng-repeat="filter in filters | filter: filters"
and inside my filters something like that to work
ng-repeat="...| filter:{dev:java, happy:true}"
So can i do it in the way i'm trying to do or i have to create a filter module?
Upvotes: 1
Views: 40
Reputation: 193271
The simplest thing you can do is to use simple object for filters instead of array, where filter name would be a property key. In this case you would render filters like this:
<span class="btn btn-success" ng-repeat="(name, value) in filters">
<strong>{{name}} : {{value}}</strong>
</span>
and populate them in controller like this:
$scope.createFilter = function(name, value) {
$scope.filters[name] = value;
$scope.cleanInput();
};
With this setup it's very easy to apply filters to the table data:
ng-repeat="user in users | filter:filters"
Demo: http://plnkr.co/edit/Hp8EPpvHv8vklSiFOG6U?p=info
Upvotes: 1